diff options
Diffstat (limited to 'modules')
105 files changed, 2118 insertions, 14119 deletions
diff --git a/modules/chibi/SCsub b/modules/chibi/SCsub deleted file mode 100644 index dffd96675..000000000 --- a/modules/chibi/SCsub +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env python - -Import('env') -Import('env_modules') - -env_chibi = env_modules.Clone() - -# Godot source files -env_chibi.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/chibi/cp_config.h b/modules/chibi/cp_config.h deleted file mode 100644 index 35312b68b..000000000 --- a/modules/chibi/cp_config.h +++ /dev/null @@ -1,52 +0,0 @@ -/*************************************************************************/ -/* cp_config.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef CP_CONFIG_H -#define CP_CONFIG_H - - -#include "typedefs.h" -#include "error_macros.h" -#include "math_funcs.h" -#include "os/memory.h" -#include "os/copymem.h" - -#define CP_PRINTERR(m_err) ERR_PRINT(m_err) -#define CP_ERR_COND(m_cond) ERR_FAIL_COND(m_cond) -#define CP_ERR_COND_V(m_cond,m_ret) ERR_FAIL_COND_V(m_cond,m_ret) -#define CP_FAIL_INDEX(m_index,m_size) ERR_FAIL_INDEX(m_index,m_size) -#define CP_FAIL_INDEX_V(m_index,m_size,m_ret) ERR_FAIL_INDEX_V(m_index,m_size,m_ret) -#define cp_intabs(m_val) ABS(m_val) - -#define CP_ALLOC(m_mem) memalloc(m_mem) -#define CP_REALLOC(m_mem,m_size) memrealloc(m_mem,m_size) -#define CP_FREE(m_mem) memfree(m_mem) - -#define cp_memzero(m_mem,m_size) zeromem(m_mem,m_size) - -#endif // CP_CONFIG_H diff --git a/modules/chibi/cp_envelope.cpp b/modules/chibi/cp_envelope.cpp deleted file mode 100644 index 36259e8d6..000000000 --- a/modules/chibi/cp_envelope.cpp +++ /dev/null @@ -1,369 +0,0 @@ -/*************************************************************************/ -/* cp_envelope.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "cp_envelope.h" - - -CPEnvelope::CPEnvelope() { - - - reset(); -} - -void CPEnvelope::reset() { - - - - on=false; - carry=false; - loop_on=false; - loop_begin_node=0; - loop_end_node=0; - sustain_loop_on=false; - sustain_loop_begin_node=0; - sustain_loop_end_node=0; - node_count=0; - -} - -int CPEnvelope::get_height_at_pos(int pos) { - - if (node_count && pos>node[node_count-1].tick_offset) - return node[node_count-1].value; - - int begin_x,begin_y; - int end_x,end_y,xdif; - int count=0; - int limit=-1; - - if (node_count<2) return NO_POINT; - - while ((count<node_count) && (limit==-1)) { - - if (node[count].tick_offset>=pos) limit=count; - count++; - } - - if (pos==0) return node[0].value; - - if (limit==-1) return NO_POINT; - - begin_x=node[limit-1].tick_offset; - end_x=node[limit].tick_offset; - begin_y=node[limit-1].value; - end_y=node[limit].value; - - xdif=end_x-begin_x; - return begin_y+((pos-begin_x)*(end_y-begin_y))/(xdif?xdif:1); -} - -/* -int CPEnvelope::get_fx_height_at_pos(int pos) { - - if (node_count && pos>node[node_count-1].tick_offset) - return node[node_count-1].value<<FX_HEIGHT_BITS; - - int begin_x,begin_y; - int end_x,end_y,xdif; - int count=0; - int limit=-1; - - if (node_count<2) return NO_POINT; - - while ((count<node_count) && (limit==-1)) { - - if (node[count].tick_offset>=pos) limit=count; - count++; - } - - if (pos==0) return node[0].value<<FX_HEIGHT_BITS; - - if (limit==-1) return NO_POINT; - - begin_x=node[limit-1].tick_offset; - end_x=node[limit].tick_offset; - begin_y=node[limit-1].value; - end_y=node[limit].value; - - xdif=end_x-begin_x; - return (begin_y<<FX_HEIGHT_BITS)+((pos-begin_x)*(end_y-begin_y)*(int)(1<<FX_HEIGHT_BITS))/(xdif?xdif:1); -} -*/ - -float CPEnvelope::get_interp_height_at_pos(float pos) { - - if (node_count && pos>node[node_count-1].tick_offset) - return node[node_count-1].value; - - int begin_x,begin_y; - int end_x,end_y,xdif; - int count=0; - int limit=-1; - - if (node_count<2) return NO_POINT; - - while ((count<node_count) && (limit==-1)) { - - if (node[count].tick_offset>=pos) limit=count; - count++; - } - - if (pos==0) return node[0].value; - - if (limit==-1) return NO_POINT; - - begin_x=node[limit-1].tick_offset; - end_x=node[limit].tick_offset; - begin_y=node[limit-1].value; - end_y=node[limit].value; - - xdif=end_x-begin_x; - return begin_y+((pos-begin_x)*(end_y-begin_y))/(xdif?xdif:1); -} - -void CPEnvelope::set_position(int p_node,int p_x,int p_y) { - - if (p_node>=node_count) return; - - - - if (p_node==0) { - - p_x=0; - - } else if (p_x<=node[p_node-1].tick_offset) { - - p_x=node[p_node-1].tick_offset+1; - - } else if ((p_node<(node_count-1)) && (p_x>=node[p_node+1].tick_offset)) { - - p_x=node[p_node+1].tick_offset-1; - } - - if (p_x>=9999) p_x=9999; - - if (p_y>max_value) p_y=max_value; - if (p_y<min_value) p_y=min_value; - - - node[p_node].tick_offset=p_x; - node[p_node].value=p_y; - - - -} - -int CPEnvelope::add_position(int p_x,int p_y,bool p_move_loops) { - - if (node_count==MAX_POINTS) return -1; - - - int i,new_node; - - // if this is assigning an existing node, let's quit. - for (i=0;i<node_count;i++) if (p_x==node[i].tick_offset) return -1; - - - i=0; - while ((i<node_count) && (p_x>=node[i].tick_offset)) i++; - - new_node=i; - node_count++; - - if (p_move_loops) { - if (loop_begin_node>=new_node) loop_begin_node++; - if (loop_end_node>=new_node) loop_end_node++; - if (sustain_loop_begin_node>=new_node) sustain_loop_begin_node++; - if (sustain_loop_end_node>=new_node) sustain_loop_end_node++; - } - for (i=node_count-1;i>new_node;i--) node[i]=node[i-1]; - - - - set_position(new_node,p_x,p_y); - - - - return new_node; - -} - -void CPEnvelope::set_loop_begin(int pos) { - - if ((pos<0) || (pos>=node_count)) return; - - - - loop_begin_node=pos; - - if (loop_end_node<loop_begin_node) loop_end_node=loop_begin_node; - - - -} - -void CPEnvelope::set_loop_end(int pos) { - - if ((pos<0) || (pos>=node_count)) return; - - - - loop_end_node=pos; - - if (loop_end_node<loop_begin_node) loop_begin_node=loop_end_node; - - - - -} - - -void CPEnvelope::set_sustain_loop_begin(int pos) { - - if ((pos<0) || (pos>=node_count)) return; - - - - sustain_loop_begin_node=pos; - - if (sustain_loop_end_node<sustain_loop_begin_node) sustain_loop_end_node=sustain_loop_begin_node; - - - -} - -void CPEnvelope::set_sustain_loop_end(int pos) { - - if ((pos<0) || (pos>=node_count)) return; - - - - sustain_loop_end_node=pos; - - if (sustain_loop_end_node<sustain_loop_begin_node) sustain_loop_begin_node=sustain_loop_end_node; - - - -} - -void CPEnvelope::set_loop_enabled(bool p_enabled) { - - loop_on=p_enabled; -} -bool CPEnvelope::is_loop_enabled() { - - return loop_on; -} - - -void CPEnvelope::set_sustain_loop_enabled(bool p_enabled) { - - sustain_loop_on=p_enabled; -} -bool CPEnvelope::is_sustain_loop_enabled() { - - return sustain_loop_on; -} - -void CPEnvelope::del_position(int p_node) { - - if ((node_count<3) || (p_node<=0) || (p_node>=node_count)) return; - - - - int i; - - if (loop_begin_node>=p_node) loop_begin_node--; - if (loop_end_node>=p_node) loop_end_node--; - if (sustain_loop_begin_node>=p_node) sustain_loop_begin_node--; - if (sustain_loop_end_node>=p_node) sustain_loop_end_node--; - - for (i=p_node;i<node_count-1;i++) node[i]=node[i+1]; - - node_count--; - - - -} - -uint8_t CPEnvelope::get_loop_begin() { - - - return loop_begin_node; -} -uint8_t CPEnvelope::get_loop_end() { - - return loop_end_node; -} - -uint8_t CPEnvelope::get_sustain_loop_begin() { - - - return sustain_loop_begin_node; -} -uint8_t CPEnvelope::get_sustain_loop_end() { - - return sustain_loop_end_node; -} - - - -void CPEnvelope::set_enabled(bool p_enabled) { - - on=p_enabled; -} - -bool CPEnvelope::is_enabled() { - - return on; -} - -void CPEnvelope::set_carry_enabled(bool p_enabled) { - - carry=p_enabled; -} -bool CPEnvelope::is_carry_enabled() { - - return carry; -} - -uint8_t CPEnvelope::get_node_count() { - - return node_count; -} - -const CPEnvelope::Point& CPEnvelope::get_node(int p_idx) { - - if (p_idx<0 || p_idx>=node_count) - return node[node_count-1]; - - return node[p_idx]; - -} - - diff --git a/modules/chibi/cp_envelope.h b/modules/chibi/cp_envelope.h deleted file mode 100644 index af27f5f18..000000000 --- a/modules/chibi/cp_envelope.h +++ /dev/null @@ -1,129 +0,0 @@ -/*************************************************************************/ -/* cp_envelope.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef CP_ENVELOPE_H -#define CP_ENVELOPE_H - -#include "cp_config.h" - -/**envelope? - *@author Juan Linietsky - */ - -/****************************** - envelope.h - ---------- - -Proovides an envelope, and basic functions -for it that can be used for both player -and interface -********************************/ - - -class CPEnvelope { - enum { - - MAX_POINTS=25 - }; - - struct Point { - - uint16_t tick_offset; - int16_t value; - }; - - Point node[MAX_POINTS]; - - int8_t node_count; - - bool on; - bool carry; - - bool loop_on; - - uint8_t loop_begin_node; - uint8_t loop_end_node; - - bool sustain_loop_on; - uint8_t sustain_loop_begin_node; - uint8_t sustain_loop_end_node; - - - int8_t max_value; - int8_t min_value; - - -public: - enum { - - NO_POINT=-5000, - }; - - void set_max(int8_t p_max) { max_value=p_max; } - int8_t get_max() { return max_value; } - void set_min(int8_t p_min) { min_value=p_min; } - int8_t get_min() { return min_value; } - - uint8_t get_node_count(); - const Point& get_node(int p_idx); - - void set_position(int p_node,int p_x,int p_y); - int add_position(int p_x,int p_y,bool p_move_loops=true); - void del_position(int p_node); - - void set_loop_enabled(bool p_enabled); - bool is_loop_enabled(); - void set_loop_begin(int pos); - void set_loop_end(int pos); - uint8_t get_loop_begin(); - uint8_t get_loop_end(); - - void set_sustain_loop_enabled(bool p_enabled); - bool is_sustain_loop_enabled(); - void set_sustain_loop_begin(int pos); - void set_sustain_loop_end(int pos); - uint8_t get_sustain_loop_begin(); - uint8_t get_sustain_loop_end(); - - void set_enabled(bool p_enabled); - bool is_enabled(); - - void set_carry_enabled(bool p_enabled); - bool is_carry_enabled(); - - void reset(); - int get_height_at_pos(int pos); - float get_interp_height_at_pos(float pos); - - - CPEnvelope(); - -}; - -#endif diff --git a/modules/chibi/cp_file_access_wrapper.h b/modules/chibi/cp_file_access_wrapper.h deleted file mode 100644 index ade077c1e..000000000 --- a/modules/chibi/cp_file_access_wrapper.h +++ /dev/null @@ -1,96 +0,0 @@ -/*************************************************************************/ -/* cp_file_access_wrapper.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef CP_FILE_ACCESS_WRAPPER_H -#define CP_FILE_ACCESS_WRAPPER_H - -#include "cp_config.h" - -class CPFileAccessWrapper { -public: - - enum ModeFlags { - - READ=1, - WRITE=2, - READ_WRITE=3, - }; - - enum Error { - - OK, - ERROR_FILE_NOT_FOUND, - ERROR_FILE_BAD_DRIVE, - ERROR_FILE_BAD_PATH, - ERROR_FILE_NO_PERMISSION, - ERROR_ALREADY_IN_USE, - ERROR_INVALID_PARAMETERS, - ERROR_OPENING_FILE, - ERROR_READING_FILE, - ERROR_WRITING_FILE - }; - - virtual Error open(const char *p_filename, int p_mode_flags)=0; - virtual void close()=0; - - virtual void seek(uint32_t p_position)=0; - virtual void seek_end()=0; - virtual uint32_t get_pos()=0; - - virtual bool eof_reached()=0; - - virtual uint8_t get_byte()=0; - virtual void get_byte_array(uint8_t *p_dest,int p_elements)=0; - virtual void get_word_array(uint16_t *p_dest,int p_elements)=0; - - virtual uint16_t get_word()=0; - virtual uint32_t get_dword()=0; - - // use this for files WRITTEN in _big_ endian machines (ie, amiga/mac) - // It's not about the current CPU type but file formats. - // this flags get reset to false (little endian) on each open - virtual void set_endian_conversion(bool p_swap)=0; - virtual bool is_open()=0; - - virtual Error get_error()=0; - - virtual void store_byte(uint8_t p_dest)=0; - virtual void store_byte_array(const uint8_t *p_dest,int p_elements)=0; - - virtual void store_word(uint16_t p_dest)=0; - virtual void store_dword(uint32_t p_dest)=0; - - - - virtual ~CPFileAccessWrapper(){} - -}; - - - -#endif diff --git a/modules/chibi/cp_instrument.cpp b/modules/chibi/cp_instrument.cpp deleted file mode 100644 index 606a4217e..000000000 --- a/modules/chibi/cp_instrument.cpp +++ /dev/null @@ -1,344 +0,0 @@ -/*************************************************************************/ -/* cp_instrument.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "cp_instrument.h" -#include "cp_song.h" -#include "cp_note.h" - - - -const char *CPInstrument::get_name() { - - return name; - -} -void CPInstrument::set_name(const char *p_name) { - - - if (p_name==NULL) { - name[0]=0; - return; - } - - - bool done=false; - for (int i=0;i<MAX_NAME_LEN;i++) { - - - name[i]=done?0:p_name[i]; - if (!done && p_name[i]==0) - done=true; - } - - name[MAX_NAME_LEN-1]=0; /* just in case */ - - -} - -void CPInstrument::set_sample_number(uint8_t p_note,uint8_t p_sample_id) { - - CP_ERR_COND(p_note>=CPNote::NOTES); - CP_ERR_COND(p_sample_id>CPSong::MAX_SAMPLES && p_sample_id!=CPNote::EMPTY); - data.sample_number[p_note]=p_sample_id; - - -} -uint8_t CPInstrument::get_sample_number(uint8_t p_note) { - - CP_ERR_COND_V(p_note>=CPNote::NOTES,0); - return data.sample_number[p_note]; -} - -void CPInstrument::set_note_number(uint8_t p_note,uint8_t p_note_id) { - - CP_ERR_COND(p_note>=CPNote::NOTES); - CP_ERR_COND(p_note_id>=CPNote::NOTES && p_note_id!=CPNote::EMPTY); - data.note_number[p_note]=p_note_id; - -} -uint8_t CPInstrument::get_note_number(uint8_t p_note) { - - CP_ERR_COND_V(p_note>=CPNote::NOTES,0); - return data.note_number[p_note]; - -} - -void CPInstrument::set_NNA_type(NNA_Type p_NNA_type) { - - data.NNA_type=p_NNA_type; -} -CPInstrument::NNA_Type CPInstrument::get_NNA_type() { - - return data.NNA_type; -} - -void CPInstrument::set_DC_type(DC_Type p_DC_type) { - - data.DC_type=p_DC_type; -} -CPInstrument::DC_Type CPInstrument::get_DC_type() { - - return data.DC_type; - -} - -void CPInstrument::set_DC_action(DC_Action p_DC_action) { - - data.DC_action=p_DC_action; -} -CPInstrument::DC_Action CPInstrument::get_DC_action() { - - return data.DC_action; -} - -/* Volume */ - -void CPInstrument::set_volume_global_amount(uint8_t p_amount) { - - CP_ERR_COND(p_amount>MAX_VOLUME); - data.volume.global_amount=p_amount; - -} -uint8_t CPInstrument::get_volume_global_amount() { - - return data.volume.global_amount; -} - -void CPInstrument::set_volume_fadeout(uint16_t p_amount) { - CP_ERR_COND(p_amount>MAX_FADEOUT); - data.volume.fadeout=p_amount; -} -uint16_t CPInstrument::get_volume_fadeout() { - - return data.volume.fadeout; -} -void CPInstrument::set_volume_random_variation(uint8_t p_amount) { - - CP_ERR_COND(p_amount>MAX_VOLUME_RANDOM); - data.volume.random_variation=p_amount; -} -uint8_t CPInstrument::get_volume_random_variation() { - - return data.volume.random_variation; -} - -/* Panning */ - -void CPInstrument::set_pan_default_amount(uint8_t p_amount) { - - CP_ERR_COND(p_amount>MAX_PAN); - data.pan.default_amount=p_amount; -} -uint8_t CPInstrument::get_pan_default_amount() { - - return data.pan.default_amount; -} - -void CPInstrument::set_pan_default_enabled(bool p_enabled) { - - data.pan.use_default=p_enabled; -} -bool CPInstrument::is_pan_default_enabled() { - - return data.pan.use_default; - -} - -void CPInstrument::set_pan_pitch_separation(int8_t p_amount) { - - CP_ERR_COND(p_amount<-32); - CP_ERR_COND(p_amount>32); - data.pan.pitch_separation=p_amount; -} -int8_t CPInstrument::get_pan_pitch_separation() { - - return data.pan.pitch_separation; -} - -void CPInstrument::set_pan_pitch_center(uint8_t p_amount) { - - CP_ERR_COND(p_amount>=CPNote::NOTES); - data.pan.pitch_center=p_amount; -} -uint8_t CPInstrument::get_pan_pitch_center() { - - return data.pan.pitch_center; -} - -void CPInstrument::set_pan_random_variation(uint8_t p_amount) { - - CP_ERR_COND(p_amount>MAX_PAN_RANDOM); - data.pan.random_variation=p_amount; -} -uint8_t CPInstrument::get_pan_random_variation() { - - return data.pan.random_variation; -} - -/* Pitch / Filter */ - -void CPInstrument::set_pitch_use_as_filter(bool p_enabled) { - - data.pitch.use_as_filter=p_enabled; -} -bool CPInstrument::is_pitch_use_as_filter() { - - return data.pitch.use_as_filter; -} - -void CPInstrument::set_filter_use_default_cutoff(bool p_enabled) { - - data.pitch.use_default_cutoff=p_enabled; - -} -bool CPInstrument::filter_use_default_cutoff() { - - return data.pitch.use_default_cutoff; -} - -void CPInstrument::set_filter_default_cutoff(uint8_t p_amount) { - - CP_ERR_COND(p_amount>MAX_FILTER_CUTOFF); - data.pitch.default_cutoff=p_amount; -} -uint8_t CPInstrument::get_filter_default_cutoff() { - - return data.pitch.default_cutoff; -} - -void CPInstrument::set_filter_use_default_resonance(bool p_enabled) { - - data.pitch.use_default_resonance=p_enabled; -} -bool CPInstrument::filter_use_default_resonance() { - - return data.pitch.use_default_resonance; -} - -void CPInstrument::set_filter_default_resonance(uint8_t p_amount) { - - CP_ERR_COND(p_amount>MAX_FILTER_RESONANCE); - data.pitch.default_resonance=p_amount; - -} -uint8_t CPInstrument::get_filter_default_resonance() { - - return data.pitch.default_resonance; -} - -/* Envelopes */ - - -CPEnvelope* CPInstrument::get_volume_envelope() { - - return &data.volume.envelope; -} -CPEnvelope* CPInstrument::get_pan_envelope() { - - return &data.pan.envelope; -} -CPEnvelope* CPInstrument::get_pitch_filter_envelope() { - - return &data.pitch.envelope; - - -} - - -void CPInstrument::reset() { - - name[0]=0; - - data.NNA_type=NNA_NOTE_CUT; - data.DC_action=DCA_NOTE_CUT; - data.DC_type=DCT_DISABLED; - - for (int i=0;i<CPNote::NOTES;i++) { - - data.sample_number[i]=CPNote::EMPTY; - data.note_number[i]=i; - } - - data.volume.envelope.reset(); - data.volume.envelope.set_max(64); - data.volume.envelope.set_min(0); - data.volume.envelope.add_position(0,64,false); - data.volume.envelope.add_position(30,64,false); - - data.volume.global_amount=MAX_VOLUME; - data.volume.fadeout=0; - data.volume.random_variation=0; - - data.pan.envelope.reset(); - data.pan.envelope.set_max(32); - data.pan.envelope.set_min(-32); - data.pan.envelope.add_position(0,0,false); - data.pan.envelope.add_position(30,0,false); - - data.pan.default_amount=32; - data.pan.pitch_center=48; - data.pan.pitch_separation=0; - data.pan.use_default=false; - data.pan.random_variation=0; - - - data.pitch.envelope.reset(); - data.pitch.envelope.set_max(32); - data.pitch.envelope.set_min(-32); - data.pitch.envelope.add_position(0,0,false); - data.pitch.envelope.add_position(30,0,false); - data.pitch.use_as_filter=false; - data.pitch.use_default_cutoff=false; - data.pitch.use_default_resonance=false; - data.pitch.default_cutoff=0; - data.pitch.default_resonance=0; - -} - -bool CPInstrument::is_empty() { - - bool has_sample=false; - - for (int i=0;i<CPNote::NOTES;i++) { - - if (data.sample_number[i]!=CPNote::EMPTY) { - - has_sample=true; - break; - } - } - - return !has_sample; -} - -CPInstrument::CPInstrument() { - - reset(); - -} - diff --git a/modules/chibi/cp_instrument.h b/modules/chibi/cp_instrument.h deleted file mode 100644 index e51612a38..000000000 --- a/modules/chibi/cp_instrument.h +++ /dev/null @@ -1,219 +0,0 @@ -/*************************************************************************/ -/* cp_instrument.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef CP_INSTRUMENT_H -#define CP_INSTRUMENT_H - - -#include "cp_config.h" -#include "cp_note.h" -#include "cp_envelope.h" - -class CPInstrument { -public: - - - enum NNA_Type { - - NNA_NOTE_CUT, - NNA_NOTE_CONTINUE, - NNA_NOTE_OFF, - NNA_NOTE_FADE - }; - - enum DC_Type { - - DCT_DISABLED, - DCT_NOTE, - DCT_SAMPLE, - DCT_INSTRUMENT - }; - - enum DC_Action - { - - DCA_NOTE_CUT, - DCA_NOTE_OFF, - DCA_NOTE_FADE, - }; - - enum EnvelopeType { - VOLUME_ENVELOPE, - PAN_ENVELOPE, - PITCH_ENVELOPE - }; - - - enum { - MAX_NAME_LEN=26, - MAX_ENVELOPE_NODES=25, - ENVELOPE_FRAC_BITS=8, - MAX_VOLUME=128, - MAX_FADEOUT=256, - MAX_PAN=128, - MAX_VOLUME_RANDOM=100, - MAX_PAN_RANDOM=64, //what did this guy have inside his head? - - MAX_FILTER_CUTOFF=127, - MAX_FILTER_RESONANCE=127 - - }; - - - struct Data { - - - uint8_t sample_number[CPNote::NOTES]; - uint8_t note_number[CPNote::NOTES]; - - NNA_Type NNA_type; - DC_Type DC_type; - DC_Action DC_action; - - struct Volume { - - CPEnvelope envelope; - uint8_t global_amount; - uint16_t fadeout; - uint8_t random_variation; - - } volume; - - struct Pan { - - CPEnvelope envelope; - bool use_default; - uint8_t default_amount; - int8_t pitch_separation; - uint8_t pitch_center; - uint8_t random_variation; - - } pan; - - struct Pitch { - - CPEnvelope envelope; - bool use_as_filter; - bool use_default_cutoff; - uint8_t default_cutoff; - bool use_default_resonance; - uint8_t default_resonance; - } pitch; - - }; - -private: - - - - Data data; - char name[MAX_NAME_LEN]; - -public: - - /* CPInstrument General */ - - const char *get_name(); - void set_name(const char *p_name); - - void set_sample_number(uint8_t p_note,uint8_t p_sample_id); - uint8_t get_sample_number(uint8_t p_note); - - void set_note_number(uint8_t p_note,uint8_t p_note_id); - uint8_t get_note_number(uint8_t p_note); - - void set_NNA_type(NNA_Type p_NNA_type); - NNA_Type get_NNA_type(); - - void set_DC_type(DC_Type p_DC_type); - DC_Type get_DC_type(); - - void set_DC_action(DC_Action p_DC_action); - DC_Action get_DC_action(); - - /* Volume */ - - void set_volume_global_amount(uint8_t p_amount); - uint8_t get_volume_global_amount(); - - void set_volume_fadeout(uint16_t p_amount); - uint16_t get_volume_fadeout(); - - void set_volume_random_variation(uint8_t p_amount); - uint8_t get_volume_random_variation(); - - /* Panning */ - - void set_pan_default_amount(uint8_t p_amount); - uint8_t get_pan_default_amount(); - - void set_pan_default_enabled(bool p_enabled); - bool is_pan_default_enabled(); - - void set_pan_pitch_separation(int8_t p_amount); - int8_t get_pan_pitch_separation(); - - void set_pan_pitch_center(uint8_t p_amount); - uint8_t get_pan_pitch_center(); - - void set_pan_random_variation(uint8_t p_amount); - uint8_t get_pan_random_variation(); - - /* Pitch / Filter */ - - void set_pitch_use_as_filter(bool p_enabled); - bool is_pitch_use_as_filter(); - - void set_filter_use_default_cutoff(bool p_enabled); - bool filter_use_default_cutoff(); - - void set_filter_default_cutoff(uint8_t p_amount); - uint8_t get_filter_default_cutoff(); - - void set_filter_use_default_resonance(bool p_enabled); - bool filter_use_default_resonance(); - - void set_filter_default_resonance(uint8_t p_amount); - uint8_t get_filter_default_resonance(); - - CPEnvelope* get_volume_envelope(); - CPEnvelope* get_pan_envelope(); - CPEnvelope* get_pitch_filter_envelope(); - - bool is_empty(); - - void reset(); - CPInstrument(); - -}; - - - -#endif - - diff --git a/modules/chibi/cp_loader.h b/modules/chibi/cp_loader.h deleted file mode 100644 index 163044448..000000000 --- a/modules/chibi/cp_loader.h +++ /dev/null @@ -1,64 +0,0 @@ -/*************************************************************************/ -/* cp_loader.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef CP_LOADER_H -#define CP_LOADER_H - - -#include "cp_song.h" -#include "cp_file_access_wrapper.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ -class CPLoader { - -public: - - enum Error { - FILE_OK, - FILE_UNRECOGNIZED, - FILE_CANNOT_OPEN, - FILE_CORRUPTED, - FILE_OUT_OF_MEMORY, - }; - - - virtual bool can_load_song()=0; - virtual bool can_load_sample()=0; - virtual bool can_load_instrument()=0; - - virtual Error load_song(const char *p_file,CPSong *p_song,bool p_sampleset)=0; - virtual Error load_sample(const char *p_file,CPSample *p_sample)=0; - virtual Error load_instrument(const char *p_file,CPSong *p_song,int p_instr_idx)=0; - - - virtual ~CPLoader() {} - -}; - -#endif diff --git a/modules/chibi/cp_loader_it.cpp b/modules/chibi/cp_loader_it.cpp deleted file mode 100644 index bfffd9b50..000000000 --- a/modules/chibi/cp_loader_it.cpp +++ /dev/null @@ -1,216 +0,0 @@ -/*************************************************************************/ -/* cp_loader_it.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "cp_loader_it.h" - -bool CPLoader_IT::can_load_song() { return true; } -bool CPLoader_IT::can_load_sample() { return true; } -bool CPLoader_IT::can_load_instrument() { return true; } - -CPLoader::Error CPLoader_IT::load_song(const char *p_file,CPSong *p_song, bool p_sampleset) { - - - song=p_song; - - if (file->open( p_file, CPFileAccessWrapper::READ )!=CPFileAccessWrapper::OK) - return CPLoader::FILE_CANNOT_OPEN; - - - Error err; - - char aux_identifier[4]; - file->get_byte_array((uint8_t*)aux_identifier,4); - - if ( aux_identifier[0]!='I' || - aux_identifier[1]!='M' || - aux_identifier[2]!='P' || - aux_identifier[3]!='M') { - - - CP_PRINTERR("IT CPLoader CPSong: Failed Identifier"); - return FILE_UNRECOGNIZED; - } - - - if (p_sampleset) { - - song->reset(false,true,true,false); - - if ((err=load_header(true))) { - file->close(); - return err; - } - - if ((err=load_samples())) { - file->close(); - return err; - } - - if ((err=load_instruments())) { - file->close(); - return err; - } - - return FILE_OK; - } - - song->reset(); - - if ((err=load_header(false))) { - file->close(); - return err; - } - - if ((err=load_orders())) { - file->close(); - return err; - } - - if ((err=load_patterns())) { - file->close(); - return err; - } - - if ((err=load_samples())) { - file->close(); - return err; - } - - if ((err=load_effects())) { - file->close(); - return err; - } - - if ((err=load_instruments())) { - file->close(); - return err; - } - - if ((err=load_message())) { - file->close(); - return err; - } - - file->close(); - return FILE_OK; - -} - - - - -CPLoader::Error CPLoader_IT::load_sample(const char *p_file,CPSample *p_sample) { - - if (file->open( p_file, CPFileAccessWrapper::READ )!=CPFileAccessWrapper::OK) - return CPLoader::FILE_CANNOT_OPEN; - - p_sample->reset(); - CPLoader::Error res=load_sample(p_sample); - - file->close(); - - return res; -} -CPLoader::Error CPLoader_IT::load_instrument(const char *p_file,CPSong *p_song,int p_instr_idx) { - - CP_FAIL_INDEX_V(p_instr_idx,CPSong::MAX_INSTRUMENTS,CPLoader::FILE_CANNOT_OPEN); - - if (file->open( p_file, CPFileAccessWrapper::READ )!=CPFileAccessWrapper::OK) - return CPLoader::FILE_CANNOT_OPEN; - - - p_song->get_instrument( p_instr_idx )->reset(); - - - int samples=0; - CPLoader::Error res=load_instrument( p_song->get_instrument( p_instr_idx ), &samples ); - - if (res) { - file->close(); - return res; - } - - - char exchange[CPSong::MAX_SAMPLES]; - for (int i=0;i<CPSong::MAX_SAMPLES;i++) - exchange[i]=0; - - for (int i=0;i<samples;i++) { - - file->seek( 554+i*80 ); //i think this should work?! seems to.. but i'm not sure - - /* find free sample */ - - int free_idx=-1; - for (int s=0;s<CPSong::MAX_SAMPLES;s++) { - - if (p_song->get_sample( s )->get_sample_data().is_null()) { - free_idx=s; - break; - } - } - if (free_idx==-1) - break; //can't seem to be able to load more samples - - exchange[i]=free_idx; - res=load_sample( p_song->get_sample( free_idx ) ); - - if (res) { - - file->close(); - return res; - } - } - - for (int i=0;i<CPNote::NOTES;i++) { - - int smp=song->get_instrument(p_instr_idx)->get_sample_number(i); - - if (smp>=CPSong::MAX_SAMPLES) - continue; - - if (smp<0) - continue; - - smp=exchange[smp]; - - song->get_instrument(p_instr_idx)->set_sample_number(i,smp); - - } - - file->close(); - - return res; - -} - -CPLoader_IT::CPLoader_IT(CPFileAccessWrapper *p_file) { - - file=p_file; - -} diff --git a/modules/chibi/cp_loader_it.h b/modules/chibi/cp_loader_it.h deleted file mode 100644 index 5ce62a6a4..000000000 --- a/modules/chibi/cp_loader_it.h +++ /dev/null @@ -1,125 +0,0 @@ -/*************************************************************************/ -/* cp_loader_it.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef CP_LOADER_IT_H -#define CP_LOADER_IT_H - -#include "cp_loader.h" -/** - *@author Juan Linietsky - */ - -/****************************** - loader_it.h - ---------- -Impulse Tracker Module CPLoader! -It lacks support for old -instrument files methinks... -and some other things like -midi. -********************************/ - -class AuxSampleData; //used for internal crap - -class CPLoader_IT : public CPLoader { - - - - CPFileAccessWrapper *file; - CPSong *song; - - struct IT_Header { - uint8_t blank01[2]; - uint16_t ordnum; - uint16_t insnum; - uint16_t smpnum; - uint16_t patnum; - uint16_t cwt; /* Created with tracker (y.xx = 0x0yxx) */ - uint16_t cmwt; /* Compatible with tracker ver > than val. */ - uint16_t flags; - uint16_t special; /* bit 0 set = song message attached */ - uint16_t msglength; - uint32_t msgoffset; - bool is_chibi; - }; - - /* Variables to store temp data */ - IT_Header header; - - /* CPSong Info Methods */ - Error load_header(bool p_dont_set); - Error load_orders(); - Error load_message(); - - /* CPPattern Methods */ - Error load_patterns(); - - /* CPSample Methods */ - - Error load_samples(); - Error load_sample(CPSample *p_sample); - CPSample_ID load_sample_data(AuxSampleData& p_sample_data); - - // CPSample decompression - - uint32_t read_n_bits_from_IT_compressed_block(uint8_t p_bits_to_read); - bool read_IT_compressed_block (bool p_16bits); - void free_IT_compressed_block (); - bool load_sample_8bits_IT_compressed(void *p_dest_buffer,int p_buffsize); - bool load_sample_16bits_IT_compressed(void *p_dest_buffer,int p_buffsize); - uint32_t *source_buffer; /* source buffer */ - uint32_t *source_position; /* actual reading position */ - uint8_t source_remaining_bits; /* bits remaining in read dword */ - uint8_t* pat_data; - - /* CPInstruments Methods */ - Error load_effects(); - Error load_instruments(); - Error load_instrument(CPInstrument *p_instrument,int *p_samples=0); - void load_envelope(CPEnvelope *p_envelope,bool*p_has_filter_flag=0); - - -public: - - - bool can_load_song(); - bool can_load_sample(); - bool can_load_instrument(); - - Error load_song(const char *p_file,CPSong *p_song, bool p_sampleset=false); - Error load_sample(const char *p_file,CPSample *p_sample); - Error load_instrument(const char *p_file,CPSong *p_song,int p_instr_idx); - - CPLoader_IT(CPFileAccessWrapper *p_file); - -}; - - - -#endif diff --git a/modules/chibi/cp_loader_it_info.cpp b/modules/chibi/cp_loader_it_info.cpp deleted file mode 100644 index a474fcd2f..000000000 --- a/modules/chibi/cp_loader_it_info.cpp +++ /dev/null @@ -1,268 +0,0 @@ -/*************************************************************************/ -/* cp_loader_it_info.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "cp_loader_it.h" - - - -CPLoader::Error CPLoader_IT::load_header(bool p_dont_set) { - - - char aux_songname[26]; - - file->get_byte_array((uint8_t*)aux_songname,26); - if (!p_dont_set) - song->set_name( aux_songname ); - - uint8_t aux_hlmin=file->get_byte(); - uint8_t aux_hlmaj=file->get_byte(); - - if (aux_hlmin==0) aux_hlmin=4; - if (aux_hlmaj==0) aux_hlmaj=16; - - if (!p_dont_set) { - song->set_row_highlight_minor( aux_hlmin ); - song->set_row_highlight_major( aux_hlmaj ); - } - - header.ordnum=file->get_word(); - header.insnum=file->get_word(); - header.smpnum=file->get_word(); - header.patnum=file->get_word(); - - header.cwt=file->get_word(); /* Created with tracker (y.xx = 0x0yxx) */ - header.cmwt=file->get_word(); /* Compatible with tracker ver > than val. */ - header.flags=file->get_word(); - - if (!p_dont_set) { - song->set_stereo( header.flags & 1 ); - song->set_linear_slides( header.flags & 8 ); - song->set_old_effects( header.flags & 16 ); - song->set_compatible_gxx( header.flags & 32 ); - song->set_instruments( header.flags & 4 ); - } - - - header.special=file->get_word(); - if (!p_dont_set) { - - song->set_global_volume( file->get_byte() ); - song->set_mixing_volume( file->get_byte() ); - song->set_speed( file->get_byte() ); - song->set_tempo( file->get_byte() ); - song->set_stereo_separation( file->get_byte() ); - - } else { - - file->get_byte(); // skip - file->get_byte(); // skip - file->get_byte(); // skip - file->get_byte(); // skip - file->get_byte(); // skip - } - file->get_byte(); // ZERO Byte - header.msglength=file->get_word(); - header.msgoffset=file->get_dword(); - char chibi[4]; - file->get_byte_array((uint8_t*)chibi,4); - header.is_chibi=(chibi[0]=='C' && chibi[1]=='H' && chibi[2]=='B' && chibi[3]=='I'); - - for (int i=0;i<64;i++) { - - uint8_t panbyte=file->get_byte(); - - uint8_t pan_dst=(panbyte<65) ? panbyte : 32; - bool surround_dst=(panbyte==100); - bool mute_dst=(panbyte>=128); - - if (!p_dont_set) { - song->set_channel_pan( i, pan_dst ); - song->set_channel_surround( i, surround_dst ); - song->set_channel_mute( i, mute_dst ); - } - } - for (int i=0;i<64;i++) { - unsigned char cv = file->get_byte(); - if (!p_dont_set) - song->set_channel_volume( i, cv ); - } - - CP_ERR_COND_V( file->eof_reached(),FILE_CORRUPTED ); - CP_ERR_COND_V( file->get_error(),FILE_CORRUPTED ); - - return FILE_OK; -} - -CPLoader::Error CPLoader_IT::load_effects() { - - if (!header.is_chibi) - return FILE_OK; //no effects, regular IT file - - /* GOTO End of IT header */ - file->seek(0xC0+header.ordnum+header.insnum*4+header.smpnum*4+header.patnum*4); - - - if (file->get_byte()>0) //not made with this version, ignore extended info - return FILE_OK; - - /* Chibitracker Extended info */ - - switch(file->get_byte()) { - - case CPSong::REVERB_MODE_ROOM: { - - song->set_reverb_mode( CPSong::REVERB_MODE_ROOM ); - } break; - case CPSong::REVERB_MODE_STUDIO_SMALL: { - - song->set_reverb_mode( CPSong::REVERB_MODE_STUDIO_SMALL ); - - } break; - case CPSong::REVERB_MODE_STUDIO_MEDIUM: { - - song->set_reverb_mode( CPSong::REVERB_MODE_STUDIO_MEDIUM ); - - } break; - case CPSong::REVERB_MODE_STUDIO_LARGE: { - - song->set_reverb_mode( CPSong::REVERB_MODE_STUDIO_LARGE ); - - } break; - case CPSong::REVERB_MODE_HALL: { - - song->set_reverb_mode( CPSong::REVERB_MODE_HALL ); - - } break; - case CPSong::REVERB_MODE_SPACE_ECHO: { - - song->set_reverb_mode( CPSong::REVERB_MODE_SPACE_ECHO ); - - } break; - - case CPSong::REVERB_MODE_ECHO: { - - song->set_reverb_mode( CPSong::REVERB_MODE_ECHO ); - - } break; - case CPSong::REVERB_MODE_DELAY: { - - song->set_reverb_mode( CPSong::REVERB_MODE_DELAY ); - - } break; - case CPSong::REVERB_MODE_HALF_ECHO: { - - song->set_reverb_mode( CPSong::REVERB_MODE_HALF_ECHO ); - - } break; - - } - - //chorus - song->set_chorus_speed_hz10( file->get_byte() ); - song->set_chorus_delay_ms( file->get_byte() ); - song->set_chorus_depth_ms10( file->get_byte() ); - song->set_chorus_separation_ms( file->get_byte() ); - - for (int i=0;i<CPPattern::WIDTH;i++) { - song->set_channel_reverb(i,file->get_byte()); - } - for (int i=0;i<CPPattern::WIDTH;i++) { - song->set_channel_chorus(i,file->get_byte()); - } - - return FILE_OK; - -} - -CPLoader::Error CPLoader_IT::load_message() { - - - if (!(header.special & 1)) { - - return FILE_OK; - } - - - file->seek(header.msgoffset); - - //(void*)tmpmsg=malloc(header.msglength+1); - - char message[8000]; - - - char *tmpmsg = message; - - file->get_byte_array((uint8_t*)tmpmsg,header.msglength); - tmpmsg[header.msglength]=0; - - for (int i=0;i<header.msglength;i++) if (tmpmsg[i]=='\r') tmpmsg[i]='\n'; - - song->set_message(tmpmsg); - - return FILE_OK; -} - -CPLoader::Error CPLoader_IT::load_orders() { - - file->seek(0xC0); - - - for (int i=0;i<header.ordnum;i++) { - - uint8_t aux_order=file->get_byte(); - CPOrder order=CP_ORDER_NONE; - - - if (i>=CPSong::MAX_ORDERS) - continue; - if (aux_order==254) { - - order=CP_ORDER_BREAK; - - } else if (aux_order<200) { - - order=aux_order; - //nothing! - - } - song->set_order(i,order); - - } - - if (file->eof_reached() || file->get_error()) { - - - return FILE_CORRUPTED; - - } - - return FILE_OK; -} - - - diff --git a/modules/chibi/cp_loader_it_instruments.cpp b/modules/chibi/cp_loader_it_instruments.cpp deleted file mode 100644 index 446e841c5..000000000 --- a/modules/chibi/cp_loader_it_instruments.cpp +++ /dev/null @@ -1,224 +0,0 @@ -/*************************************************************************/ -/* cp_loader_it_instruments.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "cp_loader_it.h" - -enum EnvFlags { - ENV_ON=1, - ENV_LOOP=2, - ENV_SUSLOOP=4, - ENV_CARRY=8, - ENV_FILTER=128 -}; - -void CPLoader_IT::load_envelope(CPEnvelope *p_envelope,bool*p_has_filter_flag) { - - uint8_t flags=file->get_byte(); - uint8_t points=file->get_byte(); - uint8_t begin=file->get_byte(); - uint8_t end=file->get_byte(); - uint8_t susbegin=file->get_byte(); - uint8_t susend=file->get_byte(); - - p_envelope->reset(); - - for (int i=0;i<25;i++) { - - uint8_t height=file->get_byte(); - int8_t &signed_height=(int8_t&)height; - uint16_t tick=file->get_word(); - - if (i>=points) - continue; - p_envelope->add_position( tick, signed_height ); - - } - - p_envelope->set_enabled( flags & ENV_ON ); - p_envelope->set_carry_enabled( flags & ENV_CARRY); - - p_envelope->set_loop_enabled( flags & ENV_LOOP ); - p_envelope->set_loop_begin( begin ); - p_envelope->set_loop_end( end ); - - p_envelope->set_sustain_loop_enabled( flags & ENV_SUSLOOP ); - p_envelope->set_sustain_loop_begin( susbegin ); - p_envelope->set_sustain_loop_end( susend ); - - if (p_has_filter_flag) - *p_has_filter_flag=flags&ENV_FILTER; - - file->get_byte(); //zerobyte - - //fill with stuff if the envelope hass less than 2 points - while(p_envelope->get_node_count()<2) { - - p_envelope->add_position( 30*p_envelope->get_node_count(), p_envelope->get_min()==0 ? 64 : 0, false ); - } -} - - -CPLoader::Error CPLoader_IT::load_instrument(CPInstrument *p_instrument,int *p_samples) { - - - - char aux_header[4]; - - file->get_byte_array((uint8_t*)aux_header,4); - - - if ( aux_header[0]!='I' || - aux_header[1]!='M' || - aux_header[2]!='P' || - aux_header[3]!='I') { - CP_PRINTERR("IT CPLoader CPInstrument: Failed Identifier"); - - return FILE_UNRECOGNIZED; - } - - - - // Ignore deprecated 8.3 filename field - for (int i=0;i<12;i++) file->get_byte(); - - //Ignore zerobyte - file->get_byte(); /* (byte) CPInstrument type (always 0) */ - - switch( file->get_byte() ) { /* New CPNote Action [0,1,2,3] */ - case 0: p_instrument->set_NNA_type( CPInstrument::NNA_NOTE_CUT ) ; break; - case 1: p_instrument->set_NNA_type( CPInstrument::NNA_NOTE_CONTINUE ) ; break; - case 2: p_instrument->set_NNA_type( CPInstrument::NNA_NOTE_OFF ) ; break; - case 3: p_instrument->set_NNA_type( CPInstrument::NNA_NOTE_FADE ) ; break; - }; - switch( file->get_byte() ) { // Duplicate Check Type - case 0: p_instrument->set_DC_type( CPInstrument::DCT_DISABLED ); break ; - case 1: p_instrument->set_DC_type( CPInstrument::DCT_NOTE ); break ; - case 2: p_instrument->set_DC_type( CPInstrument::DCT_SAMPLE ); break ; - case 3: p_instrument->set_DC_type( CPInstrument::DCT_INSTRUMENT ); break ; - } - switch( file->get_byte() ) { //Duplicate Check Action - case 0: p_instrument->set_DC_action( CPInstrument::DCA_NOTE_CUT ); break ; - case 1: p_instrument->set_DC_action( CPInstrument::DCA_NOTE_OFF ); break ; - case 2: p_instrument->set_DC_action( CPInstrument::DCA_NOTE_FADE ); break ; - } - - int fade = file->get_word(); - //intf("AFADE: %i\n",fade); - if (fade>CPInstrument::MAX_FADEOUT) //needs to be clipped because of horrible modplug doings - fade=CPInstrument::MAX_FADEOUT; - - p_instrument->set_volume_fadeout( fade ); - p_instrument->set_pan_pitch_separation( file->get_byte() ); - p_instrument->set_pan_pitch_center( file->get_byte() ); - p_instrument->set_volume_global_amount( file->get_byte() ); - uint8_t pan=file->get_byte(); - p_instrument->set_pan_default_amount(pan&0x7F); - p_instrument->set_pan_default_enabled( !(pan&0x80) ); - p_instrument->set_volume_random_variation( file->get_byte() ); - p_instrument->set_pan_random_variation( file->get_byte() ); - - - - file->get_word(); //empty (version) - uint8_t samples=file->get_byte(); - if (p_samples) - *p_samples=samples; - file->get_byte(); //empty - char aux_name[26]; - file->get_byte_array((uint8_t*)aux_name,26); - p_instrument->set_name(aux_name); - - uint8_t cutoff=file->get_byte(); - - p_instrument->set_filter_default_cutoff(cutoff&0x7F); - p_instrument->set_filter_use_default_cutoff(cutoff&0x80); - - uint8_t resonance=file->get_byte(); - - p_instrument->set_filter_default_resonance(resonance&0x7F); - p_instrument->set_filter_use_default_resonance(resonance&0x80); - - file->get_dword(); //MIDI, IGNORED! - - /* CPNote -> CPSample table */ - for (uint8_t i=0;i<CPNote::NOTES;i++) { - - - uint8_t note=file->get_byte(); - if (note>=CPNote::NOTES) - note=0; - p_instrument->set_note_number(i,note); - - uint8_t samp=file->get_byte(); - if (samp==0 || samp>99) - samp=CPNote::EMPTY; - else - samp--; - - - p_instrument->set_sample_number(i,samp); - - - } - - - load_envelope( p_instrument->get_volume_envelope() ); - load_envelope( p_instrument->get_pan_envelope() ); - bool use_as_filter; - load_envelope( p_instrument->get_pitch_filter_envelope(), &use_as_filter ); - p_instrument->set_pitch_use_as_filter( use_as_filter ); - - return FILE_OK; - -} - - -CPLoader::Error CPLoader_IT::load_instruments() { - - - for (int i=0;i<header.insnum;i++) { - - - file->seek(0xC0+header.ordnum+i*4); - uint32_t final_location=file->get_dword(); - file->seek( final_location ); - - Error err=load_instrument( song->get_instrument( i ) ); - if (err) - return err; - - } - - return FILE_OK; - - if (file->eof_reached() || file->get_error()) - return FILE_CORRUPTED; -} - - diff --git a/modules/chibi/cp_loader_it_patterns.cpp b/modules/chibi/cp_loader_it_patterns.cpp deleted file mode 100644 index 528d99fff..000000000 --- a/modules/chibi/cp_loader_it_patterns.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/*************************************************************************/ -/* cp_loader_it_patterns.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "cp_loader_it.h" - - -CPLoader::Error CPLoader_IT::load_patterns() { - - - for (int i=0;i<header.patnum;i++) { - - if (i>=CPSong::MAX_PATTERNS) - break; - - /* Position where pattern offsets are stored */ - file->seek(0xC0+header.ordnum+header.insnum*4+header.smpnum*4+i*4); - uint32_t pattern_offset=file->get_dword(); - - if (pattern_offset==0) { - - continue; - } - - uint16_t pat_size; - uint16_t pat_length; - - int row=0,flag,channel,j; - uint8_t aux_byte; - uint32_t reserved; - uint8_t chan_mask[64]; //mask cache for each - CPNote last_value[64]; //last value of each - - for (j=0;j<64;j++) { - - chan_mask[j]=0; - last_value[j].clear(); - } - - file->seek(pattern_offset); - - pat_size=file->get_word(); - pat_length=file->get_word(); - reserved=file->get_dword(); - - song->get_pattern(i)->set_length( pat_length ); - - do { - - aux_byte=file->get_byte(); - flag=aux_byte; - - if ( flag==0 ) { - - row++; - } else { - - channel=(flag-1) & 63; - - if ( flag & 128 ) { - - aux_byte=file->get_byte(); - chan_mask[channel]=aux_byte; - } - - CPNote note; //note used for reading - - if ( chan_mask[channel]&1 ) { // read note - - aux_byte=file->get_byte(); - - if ( aux_byte<120 ) - note.note=aux_byte; - else if ( aux_byte==255 ) - note.note=CPNote::OFF; - else if ( aux_byte==254 ) - note.note=CPNote::CUT; - - last_value[channel].note=note.note; - } - - - if ( chan_mask[channel]&2 ) { - - aux_byte=file->get_byte(); - if ( aux_byte<100 ) - note.instrument=aux_byte-1; - - last_value[channel].instrument=note.instrument; - } - if ( chan_mask[channel]&4 ) { - - aux_byte=file->get_byte(); - if ( aux_byte<213 ) - note.volume=aux_byte; - - last_value[channel].volume=note.volume; - } - if ( chan_mask[channel]&8 ) { - - aux_byte=file->get_byte(); - if ( aux_byte>0 ) - note.command=aux_byte-1; - - - last_value[channel].command=note.command; - - note.parameter=file->get_byte(); - - last_value[channel].parameter=note.parameter; - } - - if ( chan_mask[channel]&16 ) { - - note.note=last_value[channel].note; - } - - if ( chan_mask[channel]&32 ) { - - note.instrument=last_value[channel].instrument; - } - if ( chan_mask[channel]&64 ) { - - note.volume=last_value[channel].volume; - } - if ( chan_mask[channel]&128 ) { - - note.command=last_value[channel].command; - note.parameter=last_value[channel].parameter; - } - - song->get_pattern(i)->set_note(channel,row,note); - } - - - } while(row<pat_length); - - } - - return FILE_OK; -} - diff --git a/modules/chibi/cp_loader_it_samples.cpp b/modules/chibi/cp_loader_it_samples.cpp deleted file mode 100644 index 60db9b7f7..000000000 --- a/modules/chibi/cp_loader_it_samples.cpp +++ /dev/null @@ -1,620 +0,0 @@ -/*************************************************************************/ -/* cp_loader_it_samples.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "cp_loader_it.h" -#include "cp_sample.h" - -struct AuxSampleData { - - - uint32_t fileofs; - uint32_t c5spd; - uint32_t length; - uint32_t loop_begin; - uint32_t loop_end; - bool loop_enabled; - bool pingpong_enabled; - bool is16bit; - bool stereo; - bool exists; - bool compressed; - -}; - - -enum IT_Sample_Flags { - - IT_SAMPLE_EXISTS=1, - IT_SAMPLE_16BITS=2, - IT_SAMPLE_STEREO=4, - IT_SAMPLE_COMPRESSED=8, - IT_SAMPLE_LOOPED=16, - IT_SAMPLE_SUSTAIN_LOOPED=32, - IT_SAMPLE_LOOP_IS_PINGPONG=64, - IT_SAMPLE_SUSTAIN_LOOP_IS_PINGPONG=128 -}; - - -CPLoader::Error CPLoader_IT::load_sample(CPSample *p_sample) { - - - AuxSampleData aux_sample_data; - - char aux_header[4]; - - file->get_byte_array((uint8_t*)aux_header,4); - - if ( aux_header[0]!='I' || - aux_header[1]!='M' || - aux_header[2]!='P' || - aux_header[3]!='S') { - - //CP_PRINTERR("IT CPLoader CPSample: Failed Identifier"); - return FILE_UNRECOGNIZED; - } - - - // Ignore deprecated 8.3 filename - for (int i=0;i<12;i++) file->get_byte(); - - file->get_byte(); //ignore zerobyte - - p_sample->set_global_volume( file->get_byte() ); - - /* SAMPLE FLAGS */ - uint8_t flags=file->get_byte(); - aux_sample_data.loop_enabled=flags&IT_SAMPLE_LOOPED; - aux_sample_data.pingpong_enabled=flags&IT_SAMPLE_LOOP_IS_PINGPONG; - aux_sample_data.is16bit=flags&IT_SAMPLE_16BITS; - aux_sample_data.exists=flags&IT_SAMPLE_EXISTS; - aux_sample_data.stereo=flags&IT_SAMPLE_STEREO; - aux_sample_data.compressed=flags&IT_SAMPLE_COMPRESSED; - - p_sample->set_default_volume(file->get_byte()); - /* SAMPLE NAME */ - char aux_name[26]; - file->get_byte_array((uint8_t*)aux_name,26); - p_sample->set_name(aux_name); - - // ?? - uint8_t convert_flag=file->get_byte(); - // PAN - uint8_t pan=file->get_byte(); - p_sample->set_pan( pan&0x7F ); - p_sample->set_pan_enabled( pan & 0x80 ); - - aux_sample_data.length=file->get_dword(); - - - aux_sample_data.loop_begin= file->get_dword(); - aux_sample_data.loop_end= file->get_dword(); - aux_sample_data.c5spd=file->get_dword(); - /*p_sample->data.set_sustain_loop_begin=*/file->get_dword(); - /*p_sample->data.sustain_loop_end=*/file->get_dword(); - aux_sample_data.fileofs=file->get_dword(); - p_sample->set_vibrato_speed( file->get_byte() ); - p_sample->set_vibrato_depth( file->get_byte() ); - p_sample->set_vibrato_rate( file->get_byte() ); - switch( file->get_byte() ) { - /* Vibrato Wave: 0=sine, 1=rampdown, 2=square, 3=random */ - case 0: p_sample->set_vibrato_type( CPSample::VIBRATO_SINE ); break; - case 1: p_sample->set_vibrato_type( CPSample::VIBRATO_SAW ); break; - case 2: p_sample->set_vibrato_type( CPSample::VIBRATO_SQUARE ); break; - case 3: p_sample->set_vibrato_type( CPSample::VIBRATO_RANDOM ); break; - default: p_sample->set_vibrato_type( CPSample::VIBRATO_SINE ); break; - } - - //printf("Name %s - Flags: fileofs :%i - c5spd %i - len %i 16b %i - data?: %i\n",p_sample->get_name(),aux_sample_data.fileofs,aux_sample_data.c5spd, aux_sample_data.length, aux_sample_data.is16bit,aux_sample_data.exists); - CPSample_ID samp_id; - - if (aux_sample_data.exists) { - samp_id=load_sample_data(aux_sample_data); - CPSampleManager::get_singleton()->set_c5_freq(samp_id,aux_sample_data.c5spd); - CPSampleManager::get_singleton()->set_loop_begin( samp_id,aux_sample_data.loop_begin ); - CPSampleManager::get_singleton()->set_loop_end( samp_id,aux_sample_data.loop_end ); - CPSample_Loop_Type loop_type=aux_sample_data.loop_enabled?( aux_sample_data.pingpong_enabled? CP_LOOP_BIDI: CP_LOOP_FORWARD):CP_LOOP_NONE; - CPSampleManager::get_singleton()->set_loop_end( samp_id,aux_sample_data.loop_end ); - CPSampleManager::get_singleton()->set_loop_type( samp_id, loop_type); - - } - - //printf("Loaded id is null?: %i\n",samp_id.is_null()); - p_sample->set_sample_data(samp_id); - if (!samp_id.is_null()) { - - // printf("Loaded ID: stereo: %i len %i 16bit %i\n",CPSampleManager::get_singleton()->is_stereo(samp_id), CPSampleManager::get_singleton()->get_size( samp_id), CPSampleManager::get_singleton()->is_16bits( samp_id) ); - } - - CP_ERR_COND_V( file->eof_reached(),FILE_CORRUPTED ); - CP_ERR_COND_V( file->get_error(),FILE_CORRUPTED ); - - return FILE_OK; - -} - -CPSample_ID CPLoader_IT::load_sample_data(AuxSampleData& p_sample_data) { - - - int aux_sample_properties = (p_sample_data.is16bit?IT_SAMPLE_16BITS:0)|(p_sample_data.compressed?IT_SAMPLE_COMPRESSED:0)|(p_sample_data.stereo?IT_SAMPLE_STEREO:0); - - file->seek(p_sample_data.fileofs); - - CPSampleManager *sm=CPSampleManager::get_singleton(); - - CPSample_ID id; - - switch (aux_sample_properties) { - - case (0): // 8 bits, mono - case (IT_SAMPLE_16BITS): // 16 bits mono - case (IT_SAMPLE_STEREO): // 8 bits stereo - case (IT_SAMPLE_16BITS|IT_SAMPLE_STEREO): { // 16 bits mono - - id=sm->create(p_sample_data.is16bit,p_sample_data.stereo,p_sample_data.length); - if (id.is_null()) - break; - - sm->lock_data(id); - - int16_t *ptr16 = (int16_t*)sm->get_data(id); - int8_t *ptr8=(int8_t*)ptr16; - - int chans=p_sample_data.stereo?2:1; - - if (p_sample_data.is16bit) { - - for (int c=0;c<chans;c++) { - - for (int i=0;i<p_sample_data.length;i++) { - - ptr16[i*chans+c]=file->get_word(); - } - } - } else { - - for (int c=0;c<chans;c++) { - - for (int i=0;i<p_sample_data.length;i++) { - - ptr8[i*chans+c]=file->get_byte(); - } - } - - } - - sm->unlock_data(id); - - } break; - case (IT_SAMPLE_COMPRESSED): { // 8 bits compressed - - - id=sm->create(false,false,p_sample_data.length); - if (id.is_null()) - break; - sm->lock_data(id); - - if ( load_sample_8bits_IT_compressed((void*)sm->get_data( id),p_sample_data.length) ) { - - sm->unlock_data(id); - sm->destroy(id); - - break; - } - - sm->unlock_data(id); - - - } break; - case (IT_SAMPLE_16BITS|IT_SAMPLE_COMPRESSED): { // 16 bits compressed - - - id=sm->create(true,false,p_sample_data.length); - if (id.is_null()) - break; - sm->lock_data(id); - - if ( load_sample_16bits_IT_compressed((void*)sm->get_data(id),p_sample_data.length) ) { - - sm->unlock_data(id); - sm->destroy(id); - break; - } - - sm->unlock_data(id); - - } break; - default: { - - // I dont know how to handle stereo compressed, does that exist? - } break; - - } - - - return id; -} - - -CPLoader::Error CPLoader_IT::load_samples() { - - for (int i=0;i<header.smpnum;i++) { - - //seek to sample - file->seek(0xC0+header.ordnum+header.insnum*4+i*4); - - uint32_t final_location=file->get_dword(); - file->seek( final_location ); - - - Error err=load_sample(song->get_sample(i)); - CP_ERR_COND_V(err,err); - - } - - if (file->eof_reached() || file->get_error()) - return FILE_CORRUPTED; - - return FILE_OK; -} -/* * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE - - -The following sample decompression code is based on xmp's code.(http://xmp.helllabs.org) which is based in openCP code. - -* NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE */ - -uint32_t CPLoader_IT::read_n_bits_from_IT_compressed_block (uint8_t p_bits_to_read) { - - uint32_t aux_return_value; - uint32_t val; - - uint8_t *buffer=(uint8_t*)source_position; - if ( p_bits_to_read <= source_remaining_bits ) { - - val=buffer[3]; - val<<=8; - val|=buffer[2]; - val<<=8; - val|=buffer[1]; - val<<=8; - val|=buffer[0]; - - aux_return_value = val & ((1 << p_bits_to_read) - 1); - val >>= p_bits_to_read; - source_remaining_bits -= p_bits_to_read; - - buffer[3]=val>>24; - buffer[2]=(val>>16)&0xFF; - buffer[1]=(val>>8)&0xFF; - buffer[0]=(val)&0xFF; - - } else { - aux_return_value=buffer[3]; - aux_return_value<<=8; - aux_return_value|=buffer[2]; - aux_return_value<<=8; - aux_return_value|=buffer[1]; - aux_return_value<<=8; - aux_return_value|=buffer[0]; - - uint32_t nbits = p_bits_to_read - source_remaining_bits; - source_position++; - - buffer+=4; - val=buffer[3]; - val<<=8; - val|=buffer[2]; - val<<=8; - val|=buffer[1]; - val<<=8; - val|=buffer[0]; - aux_return_value |= ((val & ((1 << nbits) - 1)) << source_remaining_bits); - val >>= nbits; - source_remaining_bits = 32 - nbits; - buffer[3]=val>>24; - buffer[2]=(val>>16)&0xFF; - buffer[1]=(val>>8)&0xFF; - buffer[0]=(val)&0xFF; - - } - - return aux_return_value; -} - -bool CPLoader_IT::read_IT_compressed_block (bool p_16bits) { - - uint16_t size; - - size=file->get_word(); - - if (file->eof_reached() || file->get_error()) return true; - - pat_data = (uint8_t*)CP_ALLOC( 4* ((size >> 2) + 2) ); - if (!pat_data) - return true; - - - source_buffer=(uint32_t*)pat_data; - file->get_byte_array((uint8_t*)source_buffer,size); - - if (file->eof_reached() || file->get_error()) { - - free_IT_compressed_block(); - return true; - } - - source_position = source_buffer; - source_remaining_bits = 32; - - return false; -} - -void CPLoader_IT::free_IT_compressed_block () { - - - if (pat_data) { - CP_FREE(pat_data); - pat_data=NULL; - } - -} - -bool CPLoader_IT::load_sample_8bits_IT_compressed(void *p_dest_buffer,int p_buffsize) { - - int8_t *dest_buffer; /* destination buffer which will be returned */ - uint16_t block_length; /* length of compressed data block in samples */ - uint16_t block_position; /* position in block */ - uint8_t bit_width; /* actual "bit width" */ - uint16_t aux_value; /* value read from file to be processed */ - int8_t d1, d2; /* integrator buffers (d2 for it2.15) */ - int8_t *dest_position; /* position in output buffer */ - int8_t v; /* sample value */ - bool it215; // is this an it215 module? - - dest_buffer = (int8_t *) p_dest_buffer; - - if (dest_buffer==NULL) - return true; - - for (int i=0;i<p_buffsize;i++) - dest_buffer[i]=0; - - - dest_position = dest_buffer; - - it215=(header.cmwt==0x215); - - /* now unpack data till the dest buffer is full */ - - while (p_buffsize) { - /* read a new block of compressed data and reset variables */ - if ( read_IT_compressed_block(false) ) { - CP_PRINTERR("Out of memory decompressing IT CPSample"); - return true; - } - - - block_length = (p_buffsize < 0x8000) ? p_buffsize : 0x8000; - - block_position = 0; - - bit_width = 9; /* start with width of 9 bits */ - - d1 = d2 = 0; /* reset integrator buffers */ - - /* now uncompress the data block */ - while ( block_position < block_length ) { - - aux_value = read_n_bits_from_IT_compressed_block(bit_width); /* read bits */ - - if ( bit_width < 7 ) { /* method 1 (1-6 bits) */ - - if ( aux_value == (1 << (bit_width - 1)) ) { /* check for "100..." */ - - aux_value = read_n_bits_from_IT_compressed_block(3) + 1; /* yes -> read new width; */ - bit_width = (aux_value < bit_width) ? aux_value : aux_value + 1; - /* and expand it */ - continue; /* ... next value */ - } - - } else if ( bit_width < 9 ) { /* method 2 (7-8 bits) */ - - uint8_t border = (0xFF >> (9 - bit_width)) - 4; - /* lower border for width chg */ - - if ( aux_value > border && aux_value <= (border + 8) ) { - - aux_value -= border; /* convert width to 1-8 */ - bit_width = (aux_value < bit_width) ? aux_value : aux_value + 1; - /* and expand it */ - continue; /* ... next value */ - } - - - } else if ( bit_width == 9 ) { /* method 3 (9 bits) */ - - if ( aux_value & 0x100 ) { /* bit 8 set? */ - - bit_width = (aux_value + 1) & 0xff; /* new width... */ - continue; /* ... and next value */ - } - - } else { /* illegal width, abort */ - - - free_IT_compressed_block(); - CP_PRINTERR("CPSample has illegal BitWidth "); - return true; - } - - /* now expand value to signed byte */ - if ( bit_width < 8 ) { - - uint8_t tmp_shift = 8 - bit_width; - - v=(aux_value << tmp_shift); - v>>=tmp_shift; - - } else v = (int8_t) aux_value; - - /* integrate upon the sample values */ - d1 += v; - d2 += d1; - - /* ... and store it into the buffer */ - *(dest_position++) = it215 ? d2 : d1; - block_position++; - - } - - /* now subtract block lenght from total length and go on */ - free_IT_compressed_block(); - p_buffsize -= block_length; - } - - - return false; -} - -bool CPLoader_IT::load_sample_16bits_IT_compressed(void *p_dest_buffer,int p_buffsize) { - - int16_t *dest_buffer; /* destination buffer which will be returned */ - uint16_t block_length; /* length of compressed data block in samples */ - uint16_t block_position; /* position in block */ - uint8_t bit_width; /* actual "bit width" */ - uint32_t aux_value; /* value read from file to be processed */ - int16_t d1, d2; /* integrator buffers (d2 for it2.15) */ - int16_t *dest_position; /* position in output buffer */ - int16_t v; /* sample value */ - - bool it215; // is this an it215 module? - - dest_buffer = (int16_t *) p_dest_buffer; - - if (dest_buffer==NULL) - return true; - - for (int i=0;i<p_buffsize;i++) - dest_buffer[i]=0; - - dest_position = dest_buffer; - - it215=(header.cmwt==0x215); - - - while (p_buffsize) { - /* read a new block of compressed data and reset variables */ - if ( read_IT_compressed_block(true) ) { - - return true; - } - - - block_length = (p_buffsize < 0x4000) ? p_buffsize : 0x4000; - - block_position = 0; - - bit_width = 17; /* start with width of 9 bits */ - - d1 = d2 = 0; /* reset integrator buffers */ - - while ( block_position < block_length ) { - - aux_value = read_n_bits_from_IT_compressed_block(bit_width); /* read bits */ - - if ( bit_width < 7 ) { /* method 1 (1-6 bits) */ - - if ( (signed)aux_value == (1 << (bit_width - 1)) ) { /* check for "100..." */ - - aux_value = read_n_bits_from_IT_compressed_block(4) + 1; /* yes -> read new width; */ - bit_width = (aux_value < bit_width) ? aux_value : aux_value + 1; - /* and expand it */ - continue; /* ... next value */ - } - - } else if ( bit_width < 17 ) { - - uint16_t border = (0xFFFF >> (17 - bit_width)) - 8; - - if ( (int)aux_value > (int)border && (int)aux_value <= ((int)border + 16) ) { - - aux_value -= border; /* convert width to 1-8 */ - bit_width = (aux_value < bit_width) ? aux_value : aux_value + 1; - /* and expand it */ - continue; /* ... next value */ - } - - - } else if ( bit_width == 17 ) { - - if ( aux_value & 0x10000 ) { /* bit 8 set? */ - - bit_width = (aux_value + 1) & 0xff; /* new width... */ - continue; /* ... and next value */ - } - - } else { /* illegal width, abort */ - - CP_PRINTERR("CPSample has illegal BitWidth "); - - free_IT_compressed_block(); - - return true; - } - - /* now expand value to signed byte */ - if ( bit_width < 16 ) { - - uint8_t tmp_shift = 16 - bit_width; - - v=(aux_value << tmp_shift); - v>>=tmp_shift; - - } else v = (int16_t) aux_value; - - /* integrate upon the sample values */ - d1 += v; - d2 += d1; - - /* ... and store it into the buffer */ - *(dest_position++) = it215 ? d2 : d1; - block_position++; - - } - - /* now subtract block lenght from total length and go on */ - free_IT_compressed_block(); - p_buffsize -= block_length; - } - - - return false; - -} - - - diff --git a/modules/chibi/cp_loader_mod.cpp b/modules/chibi/cp_loader_mod.cpp deleted file mode 100644 index 4a47ce5c4..000000000 --- a/modules/chibi/cp_loader_mod.cpp +++ /dev/null @@ -1,482 +0,0 @@ -/*************************************************************************/ -/* cp_loader_mod.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "cp_loader_mod.h" - - -static bool tag_equal_to(const char *p_tag, const char *p_string) { - - return( p_tag[0]==p_string[0] && - p_tag[1]==p_string[1] && - p_tag[2]==p_string[2] && - p_tag[3]==p_string[3]); -} -/* ProTracker period table */ -uint16_t period_table[6*12] = { - 1712,1616,1524,1440,1356,1280,1208,1140,1076,1016,960,907, - 856,808,762,720,678,640,604,570,538,508,480,453, - 428,404,381,360,339,320,302,285,269,254,240,226, - 214,202,190,180,170,160,151,143,135,127,120,113, - 107,101,95,90,85,80,75,71,67,63,60,56, - 53,50,47,45,42,40,37,35,33,31,30,28 -}; - - -CPLoader::Error CPLoader_MOD::load_song(const char *p_file,CPSong *p_song,bool p_sampleset) { - - if (file->open(p_file,CPFileAccessWrapper::READ)) { - //printf("Can't open file! %s\n",p_file); - return FILE_CANNOT_OPEN; - }; - - /* FIRST OF ALL, one needs to read the .mod file format tag */ - file->seek( 1080 ); //located at 1080 - - char format_tag[4]; - - file->get_byte_array( (uint8_t*)format_tag, 4 ); - - int channels=-1; - - /** THE PAIN!! - COMPARE TAGS */ - - /* Classic 4-chan */ - if (tag_equal_to(format_tag,"M.K.") ) - channels=4; - if (tag_equal_to(format_tag,"FLT4") ) - channels=4; - if (tag_equal_to(format_tag,"M!K!") ) - channels=4; - - /* 8 Channel MODS */ - - if (tag_equal_to(format_tag,"FLT8") ) - channels=2; - - if (tag_equal_to(format_tag,"CD81") ) - channels=2; - - /* Custom channel MODS */ - - for (int i=1;i<=32;i++) { - - if (i<10) { // up to 9 channels mods - - /* Old Take Tracker */ - char old_take_tracker[4]={'T','D','Z',char('0'+i)}; - - if (tag_equal_to(format_tag,old_take_tracker)) { - - channels=i; - break; - } - - /* Contemplates many XCHN Formats */ - char xchn[4]={char('0'+i),'C','H','N'}; - - if (tag_equal_to(format_tag,xchn)) { - - channels=i; - break; - } - } - - /* Fast Tracker */ - char fast_tracker[4]={char('0'+(i/10)),char('0'+(i%10)),'C','H'}; - - if (tag_equal_to(format_tag,fast_tracker)) { - - channels=i; - break; - } - - } - - - if (channels==-1) { - - file->close(); - return FILE_UNRECOGNIZED; - } - - - - /** Load CPSong INFO */ - - file->seek( 0 ); //go to begining of file - - file->set_endian_conversion( true ); - p_song->reset(); - p_song->set_instruments( false ); - - char name[21]; - - file->get_byte_array( (uint8_t*)name,20); - name[20]=0; - - p_song->set_name(name); - p_song->set_old_effects( true ); - p_song->set_linear_slides( false ); - p_song->set_compatible_gxx( true ); - - - - CPSampleManager *sm=CPSampleManager::get_singleton(); - - int instruments=31; - - for (int i=0;i<instruments;i++) { - - char sample_name[23]; - file->get_byte_array( (uint8_t*)sample_name,22); - sample_name[22]=0; - - uint32_t sample_len=file->get_word(); - sample_len<<=1; - - uint8_t fine_nibble=file->get_byte()&0xF; - - - //(int8_t)(fine_nibble & 7) - (int8_t)(fine_nibble & 8); //yesso's genius trick - // boo, I can't use it :( but i leave it here because of how cool it is - uint8_t linear_volume=file->get_byte(); //0 .. ? - - uint32_t loop_begin=file->get_word(); //0 .. ? - loop_begin<<=1; - uint32_t loop_end=file->get_word(); //0 .. ? - loop_end<<=1; - - if (sample_len>0) { - - CPSample_ID sid=sm->create( false, false, sample_len ); - - if (sid.is_null()) { - - file->close(); - return FILE_OUT_OF_MEMORY; - } - - if (loop_end>2) { - sm->set_loop_begin( sid, loop_begin ); - sm->set_loop_end( sid, loop_end+loop_begin ); - sm->set_loop_type( sid,CP_LOOP_FORWARD ); - } - static const uint16_t fine_to_freq[16]={ - 8363,8413,8463,8529,8581,8651,8723,8757, - 7895,7941,7985,8046,8107,8169,8232,8280 - }; - - sm->set_c5_freq( sid, fine_to_freq[fine_nibble] ); - p_song->get_sample(i)->set_sample_data(sid); - } - - p_song->get_sample(i)->set_name(sample_name); - p_song->get_sample(i)->set_default_volume( linear_volume ); - - - - } - - /* pan for MODs */ - for (int i=0;i<channels;i++) - p_song->set_channel_pan( i, (((i&3)==1) || ((i&3)==2)) ? 0: 64); - - - uint8_t order_count=file->get_byte(); -// uint8_t loop_to=file->get_byte(); - - - int pattern_count=0; - - for (int i=0;i<128;i++) { - - uint8_t order=file->get_byte(); - - - if (i<order_count) { - p_song->set_order(i,order); - - /* Determine the amount of patterns */ - if ((order+1)>pattern_count) - pattern_count=order+1; - } else - p_song->set_order( i, CP_ORDER_NONE ); - } - - if (instruments==31) - file->get_dword(); // identiefier, now skip it - - for (int i=0;i<pattern_count;i++) { - - for(int line=0;line<64;line++) { - - for(int column=0;column<channels;column++) { - - uint32_t note_w=file->get_dword(); - - CPNote note; - - note.instrument=(note_w>>12)&0xF; - note.instrument|=(note_w>>24)&0xF0; - - if (note.instrument==0) - note.instrument=CPNote::EMPTY; - else - note.instrument--; - - note.parameter=note_w&0xFF; - - int cmd=(note_w>>8)&0xF; - - uint32_t period=(note_w>>16)&0xFFF; - - if (period>0 && period<0xFFF) { - - //period>>=2; - //period<<=1; - for (int n=0; n<6*12; n++) { - - if (period >= period_table[n]) { - - if ((period!=period_table[n]) && (n)) - { - uint32_t p1 = period_table[n-1]; - uint32_t p2 = period_table[n]; - if (p1 - period < (period - p2)) { - - note.note=n+36; - break; - } - } - note.note=n+1+36; - break; - } - } - if (note.note==CPNote::EMPTY) - note.note=6*12+36; - - note.note--; - } - - - switch(cmd) { - - case 0x0: { - - if (note.parameter>0) - note.command='J'-'A'; - } break; - case 0x1: { - note.command='F'-'A'; - } break; - case 0x2: { - - note.command='E'-'A'; - } break; - case 0x3: { - - note.command='G'-'A'; - } break; - case 0x4: { - - note.command='H'-'A'; - } break; - case 0x5: { - note.command='L'-'A'; - } break; - case 0x6: { - - note.command='K'-'A'; - } break; - case 0x7: { - note.command='R'-'A'; - } break; - case 0x8: { - - note.command='X'-'A'; - } break; - case 0x9: { - - note.command='O'-'A'; - - } break; - case 0xA: { - - note.command='D'-'A'; - - } break; - case 0xB: { - - note.command='B'-'A'; - - } break; - case 0xC: { - - note.volume=note.parameter; - if (note.volume>64) - note.volume=64; - note.parameter=0; - - } break; - case 0xD: { - - note.command='C'-'A'; - note.parameter=(note.parameter>>4)*10 + (note.parameter&0xF); - - } break; - case 0xE: { //SPECIAL EFFECT! - - note.command='S'-'A'; - - switch(note.parameter>>4) { - - case 0x1: { - - note.command='F'-'A'; - note.parameter=0xF0|(note.parameter&0xF); - } break; - case 0x2: { - - note.command='E'-'A'; - note.parameter=0xF0|(note.parameter&0xF); - } break; - case 0x4: { - - note.command='S'-'A'; - note.parameter=0x30|(note.parameter&0x3); - - } break; - case 0x6: { - - note.command='S'-'A'; - note.parameter=0xB0|(note.parameter&0xF); - - } break; - case 0x7: { - note.command='S'-'A'; - note.parameter=0x40|(note.parameter&0x3); - - } break; - case 0x8: { - - note.command='S'-'A'; // wow, it's the same! - - } break; - case 0x9: { - note.command='Q'-'A'; - note.parameter=(note.parameter&0xF); - - } break; - case 0xA: { - - note.command='D'-'A'; - note.parameter=0xF|((note.parameter&0xF)<<4); - - } break; - case 0xB: { - note.command='D'-'A'; - note.parameter=0xF0|(note.parameter&0xF); - - } break; - case 0xC: - case 0xD: { - - note.command='S'-'A'; //wow, they are the same! - - } break; - case 0xE: { - note.command='S'-'A'; - note.parameter=0x60|(note.parameter&0xF); - - } break; - - default: { - - note.command=CPNote::EMPTY; - note.parameter=0; - } break; - - } - } break; - case 0xF: { - - if (note.parameter<32) - note.command='A'-'A'; - else - note.command='T'-'A'; - - } break; - } - - p_song->get_pattern(i)->set_note( column,line, note ); - } - } - } - - - - for (int i=0;i<instruments;i++) { - - CPSample_ID sid=p_song->get_sample(i)->get_sample_data(); - if (sid.is_null()) { - continue; //empty sample, not stored? - } - sm->lock_data(sid); - uint8_t *dataptr = (uint8_t*)sm->get_data(sid); - - int len=sm->get_size(sid); - for (int s=0;s<len;s++) { - - uint8_t d=file->get_byte(); - //d-=128; //convert to signed - int8_t*ds=(int8_t*)&d; - dataptr[s]=*ds; - - } - sm->unlock_data(sid); - } - - file->close(); - - return FILE_OK; - - -} - - -CPLoader_MOD::CPLoader_MOD(CPFileAccessWrapper *p_file) { - - file=p_file; -} - - -CPLoader_MOD::~CPLoader_MOD() -{ -} - - diff --git a/modules/chibi/cp_loader_mod.h b/modules/chibi/cp_loader_mod.h deleted file mode 100644 index 57f7128bc..000000000 --- a/modules/chibi/cp_loader_mod.h +++ /dev/null @@ -1,52 +0,0 @@ -/*************************************************************************/ -/* cp_loader_mod.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef CP_LOADER_MOD_H -#define CP_LOADER_MOD_H -#include "cp_loader.h" -/** - @author Juan Linietsky <reduz@gmail.com> -*/ -class CPLoader_MOD : public CPLoader { - - CPFileAccessWrapper *file; -public: - - bool can_load_song() { return true; } - bool can_load_sample() { return false; } - bool can_load_instrument() { return false; } - - Error load_song(const char *p_file,CPSong *p_song,bool p_sampleset); - Error load_sample(const char *p_file,CPSample *p_sample) { return FILE_UNRECOGNIZED; } - Error load_instrument(const char *p_file,CPSong *p_song,int p_instr_idx) { return FILE_UNRECOGNIZED; } - - CPLoader_MOD(CPFileAccessWrapper *p_file); - ~CPLoader_MOD(); -}; - -#endif diff --git a/modules/chibi/cp_loader_s3m.cpp b/modules/chibi/cp_loader_s3m.cpp deleted file mode 100644 index eb5fad12e..000000000 --- a/modules/chibi/cp_loader_s3m.cpp +++ /dev/null @@ -1,413 +0,0 @@ -/*************************************************************************/ -/* cp_loader_s3m.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "cp_loader_s3m.h" - -#define BITBOOL(m_exp) ((m_exp)?1:0) - - -CPLoader::Error CPLoader_S3M::load_header() { - - int i; - - - file->get_byte_array((uint8_t*)header.songname,28); - header.t1a=file->get_byte(); - header.type=file->get_byte(); - file->get_byte_array((uint8_t*)header.unused1,2); - header.ordnum=file->get_word(); - header.insnum=file->get_word(); - header.patnum=file->get_word(); - header.flags=file->get_word(); - header.tracker=file->get_word(); - header.fileformat=file->get_word(); - file->get_byte_array((uint8_t*)header.scrm,4); - header.scrm[4]=0; - - if (header.scrm[0]!='S' || header.scrm[1]!='C' || header.scrm[2]!='R' || header.scrm[3]!='M') - return FILE_UNRECOGNIZED; - - header.mastervol=file->get_byte(); - header.initspeed=file->get_byte(); - header.inittempo=file->get_byte(); - header.mastermult=file->get_byte(); - header.ultraclick=file->get_byte(); - header.pantable=file->get_byte(); - file->get_byte_array((uint8_t*)header.unused2,8); - header.special=file->get_word(); - file->get_byte_array((uint8_t*)header.channels,32); - - file->get_byte_array((uint8_t*)header.orderlist,header.ordnum); - - header.scrm[4]=0; - if (header.scrm[0]!='S' || header.scrm[1]!='C' || header.scrm[2]!='R' || header.scrm[3]!='M') //again? - return FILE_UNRECOGNIZED; - //sample parapointers - for (i=0;i<header.insnum;i++) { - - int parapointer; - parapointer=file->get_word(); - parapointer=(parapointer*16); - sample_parapointers[i]=parapointer; - } - //pattern - for (i=0;i<header.patnum;i++) { - - int parapointer; - parapointer=file->get_word(); - parapointer=(parapointer*16); - pattern_parapointers[i]=parapointer; - } - - if (header.pantable==252) { - - file->get_byte_array((uint8_t*)header.pannings,32); - } - - return FILE_OK; - - -} - - -void CPLoader_S3M::set_header() { - - - - - song->set_name( header.songname ); -// song->variables.filename= - - song->set_row_highlight_minor( 4 ); - song->set_row_highlight_major( 16 ); - song->set_mixing_volume( header.mastervol ); - song->set_linear_slides( false ); - song->set_old_effects( !(header.flags&64) ); - song->set_compatible_gxx( true ); - - song->set_global_volume( header.mastermult ); - song->set_speed( header.initspeed ); - song->set_tempo( header.inittempo ); - - //[TODO] Set Panning Positions.. ? - - for (int i=0;i<header.ordnum;i++) song->set_order(i,header.orderlist[i]); - -} - -CPLoader::Error CPLoader_S3M::load_sample(CPSample *p_sample) { - - - - int type=file->get_byte(); - - char filename[13]; - file->get_byte_array((uint8_t*)filename,12); - filename[12]=0; - - - uint32_t samplepos=(uint32_t)file->get_byte() << 16; - samplepos|=file->get_word(); - samplepos*=16; -// printf("sample at %i\n",samplepos); - /**/ - int sample_size=file->get_dword(); - - - int loop_begin=file->get_dword(); - int loop_end=file->get_dword(); - - int def_volume=file->get_byte();; - int dsk=file->get_byte(); - int pack=file->get_byte(); - - int flags=file->get_byte(); - int c2speed=file->get_dword(); - - file->get_dword(); //useless crap - file->get_dword(); - file->get_dword(); - - - char name[29]; - file->get_byte_array((uint8_t*)name,28); - name[28]=0; - - p_sample->set_default_volume(def_volume); - p_sample->set_name(name); - - char scrs[5]; - file->get_byte_array((uint8_t*)scrs,4); - scrs[4]=0; - - - - bool data_is_16bits=flags&4; - bool data_is_stereo=flags&2; - - if (type==0) { - //empty sample - return FILE_OK; - } - - - if ((type!=1) || scrs[0]!='S' || scrs[1]!='C' || scrs[2]!='R' || scrs[3]!='S' ) { -// printf("type: %i, %c%c%c%c\n",type,scrs[0],scrs[1],scrs[2],scrs[3]); - CP_PRINTERR("Not an S3M CPSample!"); - return FILE_CORRUPTED; - } - - //p_sample->data.set_c5_freq(p_sample->c2spd<<1); - - file->seek(samplepos); - - int real_sample_size=sample_size<<BITBOOL(data_is_16bits); - real_sample_size<<=BITBOOL(data_is_stereo); - - CPSampleManager *sm=CPSampleManager::get_singleton(); - - CPSample_ID id =sm->create( data_is_16bits, data_is_stereo, sample_size ); - - if (id.is_null()) - return FILE_OUT_OF_MEMORY; - - sm->lock_data(id); - void *dataptr = sm->get_data(id); - - int chans = (data_is_stereo?2:1); - for (int c=0;c<chans;c++) { - for (int i=0;i<sample_size;i++) { - - if (data_is_16bits) { - - uint16_t s=file->get_word(); - s-=32768; //toggle sign - - int16_t *v=(int16_t*)&s; - ((int16_t*)dataptr)[i*chans+c]=*v; - } else { - - - int8_t *v; - uint8_t s=file->get_byte(); - s-=128; //toggle sign - v=(int8_t*)&s; - ((int8_t*)dataptr)[i*chans+c]=*v; - - } - - } - - } - - sm->unlock_data(id); - - - sm->set_loop_begin( id, loop_begin ); - sm->set_loop_end( id, loop_end ); - sm->set_loop_type( id, (flags&1) ? CP_LOOP_FORWARD : CP_LOOP_NONE ); - sm->set_c5_freq( id, c2speed << 1 ); - p_sample->set_sample_data(id); - - /* Scream tracker previous to 3.10 seems to be buggy, as in, wont save what is after the sample loop, including the loop end point. Because of this I must fix it by habd */ - if (flags&1) { - - for (int c=0;c<(data_is_stereo?2:1);c++) { - sm->set_data( id, loop_end, sm->get_data( id, loop_begin,c ),c ); - - } - } - - - return FILE_OK; - -} - - -CPLoader::Error CPLoader_S3M::load_pattern(CPPattern *p_pattern) { - - int row=0,flag,ch; - CPNote n; - int length,accum=0; - - length=file->get_word(); - p_pattern->set_length(64); - - /* clear pattern data */ - while((row<64) && (accum<=length) ) { - flag=file->get_byte(); - accum++; - - n.clear(); - if(flag) { - // ch=remap[flag&31]; -// ch=remap[flag&31]; -// if(ch!=-1) -// n=s3mbuf[(64U*ch)+row]; -// else -// n=&dummy; - - ch=flag&31; - - if(flag&32) { - n.note=file->get_byte(); - if (n.note==255) { - - n.note=CPNote::EMPTY; - } else if (n.note==254) { - - n.note=CPNote::CUT; - } else { - - n.note=((n.note>>4)*12)+(n.note&0xF); - } - - n.instrument=file->get_byte()-1; - accum+=2; - - } - if(flag&64) { - n.volume=file->get_byte(); - if (n.volume>64) n.volume=64; - accum++; - - } - if(flag&128) { - n.command=file->get_byte()-1; - n.parameter=file->get_byte(); - accum+=2; - } - - p_pattern->set_note(ch,row,n); - } else row++; - } - return FILE_OK; - - -} - -CPLoader::Error CPLoader_S3M::load_sample(const char *p_file,CPSample *p_sample) { - - return FILE_UNRECOGNIZED; -} -CPLoader::Error CPLoader_S3M::load_instrument(const char *p_file,CPSong *p_song,int p_instr_idx) { - - return FILE_UNRECOGNIZED; - -} - - -CPLoader::Error CPLoader_S3M::load_samples() { - - int i; - - for(i=0;i<header.insnum;i++) { - - file->seek(sample_parapointers[i]); - load_sample(song->get_sample(i)); - sample_count++; - } - - return FILE_OK; -} - -CPLoader::Error CPLoader_S3M::load_patterns() { - - int i; - - Error err; - for(i=0;i<header.patnum;i++) { - - file->seek(pattern_parapointers[i]); - - err=load_pattern(song->get_pattern(i) ); - CP_ERR_COND_V(err,err); - - - pattern_count++; - } - return FILE_OK; - -} - -CPLoader::Error CPLoader_S3M::load_song(const char *p_file,CPSong *p_song,bool p_sampleset) { - - song=p_song; - - if (file->open(p_file,CPFileAccessWrapper::READ)) { - //printf("Can't open file! %s\n",p_file); - return FILE_CANNOT_OPEN; - }; - - sample_count=0; - pattern_count=0; - - //printf("LOADING HEADER\n"); - CPLoader::Error err; - if ((err=load_header())) { - file->close(); - CP_ERR_COND_V(err,err); - - } - - song->reset(); //file type recognized, reset song! - - set_header(); - - //printf("LOADING SAMPLES\n"); - - if ((err=load_samples())) { - file->close(); - - CP_ERR_COND_V(err,err); - } - - //printf("LOADING PATTERNS\n"); - - if ((err=load_patterns())) { - - file->close(); - return err; - } - - file->close(); - - return FILE_OK; -} - - - -CPLoader_S3M::CPLoader_S3M(CPFileAccessWrapper *p_file){ - - file=p_file; - -} -CPLoader_S3M::~CPLoader_S3M(){ -} - diff --git a/modules/chibi/cp_loader_s3m.h b/modules/chibi/cp_loader_s3m.h deleted file mode 100644 index 04ee0b291..000000000 --- a/modules/chibi/cp_loader_s3m.h +++ /dev/null @@ -1,111 +0,0 @@ -/*************************************************************************/ -/* cp_loader_s3m.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef CP_LOADER_S3M_H -#define CP_LOADER_S3M_H - -#include "cp_loader.h" - -/** - *@author Juan Linietsky - */ -/****************************** - loader_s3m.h - ---------- -Scream Tracker Module CPLoader! -It lacks support for -individual sample loading -and reorganizing the columns. -********************************/ - - - - -class CPLoader_S3M : public CPLoader { - - struct S3M_Header { - char songname[28]; - uint8_t t1a; - uint8_t type; - uint8_t unused1[2]; - uint16_t ordnum; - uint16_t insnum; - uint16_t patnum; - uint16_t flags; - uint16_t tracker; - uint16_t fileformat; - char scrm[5]; - uint8_t mastervol; - uint8_t initspeed; - uint8_t inittempo; - uint8_t mastermult; - uint8_t ultraclick; - uint8_t pantable; - uint8_t unused2[8]; - uint16_t special; - uint8_t channels[32]; - uint8_t pannings[32]; - uint8_t orderlist[300]; - }; - - - int sample_parapointers[CPSong::MAX_SAMPLES]; - int pattern_parapointers[CPSong::MAX_PATTERNS]; - - Error load_header(); - void set_header(); - Error load_sample(CPSample *p_sample); - Error load_pattern(CPPattern *p_pattern); - Error load_patterns(); - - Error load_samples(); - - S3M_Header header; - int sample_count; - int pattern_count; - - CPFileAccessWrapper *file; - CPSong *song; -public: - - bool can_load_song() { return true; } - bool can_load_sample() { return false; } - bool can_load_instrument() { return false; } - - Error load_song(const char *p_file,CPSong *p_song,bool p_sampleset); - Error load_sample(const char *p_file,CPSample *p_sample); - Error load_instrument(const char *p_file,CPSong *p_song,int p_instr_idx); - - CPLoader_S3M(CPFileAccessWrapper *p_file); - ~CPLoader_S3M(); -}; - - - -#endif diff --git a/modules/chibi/cp_loader_xm.cpp b/modules/chibi/cp_loader_xm.cpp deleted file mode 100644 index 65c7bc7ee..000000000 --- a/modules/chibi/cp_loader_xm.cpp +++ /dev/null @@ -1,752 +0,0 @@ -/*************************************************************************/ -/* cp_loader_xm.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "cp_loader_xm.h" -#include "cp_tables.h" - -#define ABORT_LOAD { file->close(); return FILE_CORRUPTED; } - - - - -CPLoader::Error CPLoader_XM::load_song(const char *p_file,CPSong *p_song,bool p_sampleset) { - - song=p_song; - - if (file->open(p_file,CPFileAccessWrapper::READ)) { - - return FILE_CANNOT_OPEN; - }; - - - /************************************** - LOAD HEADER - ***************************************/ - - file->get_byte_array(header.idtext,17); - header.idtext[17]=0; - - file->get_byte_array(header.songname,20); - - - - header.songname[20]=0; - header.hex1a=file->get_byte(); - if (header.hex1a!=0x1A) { //XM "magic" byte.. this sucks :) - - file->close(); - return FILE_UNRECOGNIZED; - - } - - - //magic byte sucks, but can't do much about it.. - - song->reset(); //must reset the song - - song->set_name( (const char*)header.songname ); - - file->get_byte_array(header.trackername,20); - header.trackername[20]=0; - - - header.version=file->get_word(); - - header.headersize=file->get_dword(); - - header.songlength=file->get_word(); - - header.restart_pos=file->get_word(); - - header.channels_used=file->get_word(); - - header.patterns_used=file->get_word(); - - header.instruments_used=file->get_word(); - - song->set_linear_slides( file->get_word() ); - - song->set_speed( file->get_word() ); - - song->set_tempo( file->get_word() ); - song->set_instruments( true ); - - file->get_byte_array(header.orderlist,256); - - for (int i=0;i<header.songlength;i++) { - - if (i>199) - break; - song->set_order(i,header.orderlist[i]); - } - - /************************************** - LOAD PATTERNS - ***************************************/ - - for (int i=0;i<header.patterns_used;i++) { - - uint32_t aux,rows; - - aux=file->get_dword(); //length - aux=file->get_byte(); //packing type - rows=aux=file->get_word(); //rows! - - song->get_pattern(i)->set_length( aux ); - - aux=file->get_word(); //packed size - if (aux==0) - continue; - //unpaaack! - for(int j=0;j<(int)rows;j++) - for(int k=0;k<header.channels_used;k++) { - - CPNote aux_note; - uint8_t aux_byte; - //uint8_t field; - aux_byte=file->get_byte(); //packing type - if (!(aux_byte&0x80)) { - - aux_note.note=aux_byte; - aux_byte=0xFE; //if bit 7 not set, read all of them except the note - } - - if (aux_byte&1) aux_note.note=file->get_byte(); - if (aux_byte&2) aux_note.instrument=file->get_byte(); - if (aux_byte&4) aux_note.volume=file->get_byte(); - if (aux_byte&8) aux_note.command=file->get_byte(); - if (aux_byte&16) aux_note.parameter=file->get_byte(); - - if (aux_note.note!=CPNote::EMPTY) { - - if (aux_note.note==97) aux_note.note=CPNote::OFF; - else { - aux_note.note+=11; //octave minus one (XM C-0 is 1, not zero ) - } - } - if (aux_note.instrument!=CPNote::EMPTY) { - - if ((aux_note.instrument>0) && (aux_note.instrument<100)) - aux_note.instrument--; - else - aux_note.instrument=CPNote::EMPTY; - } - if (aux_note.volume!=CPNote::EMPTY) { - - if (aux_note.volume<0x10) {} - else if (aux_note.volume<0x50) { - - aux_note.volume-=0x10; - - } else if (aux_note.volume<0x60) { - // - aux_note.volume=CPNote::EMPTY; - - } else if (aux_note.volume<0x70) { - //60 -- volume slide down - aux_note.volume-=0x60; - if (aux_note.volume>9) aux_note.volume=9; - aux_note.volume+=95; - - } else if (aux_note.volume<0x80) { - //70 -- volume slide up - aux_note.volume-=0x70; - if (aux_note.volume>9) aux_note.volume=9; - aux_note.volume+=85; - - - } else if (aux_note.volume<0x90) { - //80 -- fine volume slide down - aux_note.volume-=0x80; - if (aux_note.volume>9) aux_note.volume=9; - aux_note.volume+=75; - - - } else if (aux_note.volume<0xA0) { - //9 -- fine volume slide up - - aux_note.volume-=0x90; - if (aux_note.volume>9) aux_note.volume=9; - - aux_note.volume+=65; - - - - } else if (aux_note.volume<0xB0) { - //A -- set vibrato speed - aux_note.volume=CPNote::EMPTY; - - } else if (aux_note.volume<0xC0) { - //B -- vibrato - aux_note.volume-=0xB0; - if (aux_note.volume>9) aux_note.volume=9; - aux_note.volume+=203; - - - } else if (aux_note.volume<0xD0) { - //C -- set panning - int aux=aux_note.volume-=0xC0; - aux=aux*65/0xF; - aux_note.volume=128+aux; - - } else if (aux_note.volume<0xE0) { - aux_note.volume=CPNote::EMPTY; - - - } else if (aux_note.volume<0xF0) { - aux_note.volume=CPNote::EMPTY; - - - } else { - //F -- tone porta - aux_note.volume-=0xF0; - aux_note.volume*=9; - aux_note.volume/=0xF; - aux_note.volume+=193; - } - } - if (aux_note.command!=CPNote::EMPTY) { - - switch(aux_note.command) { - - case 0x0: - aux_note.command='J'-'A'; - break; - case 0x1: - aux_note.command='F'-'A'; - break; - case 0x2: - aux_note.command='E'-'A'; - break; - case 0x3: - aux_note.command='G'-'A'; - break; - case 0x4: - aux_note.command='H'-'A'; - break; - case 0x5: - aux_note.command='L'-'A'; - break; - case 0x6: - aux_note.command='K'-'A'; - break; - case 0x7: - aux_note.command='R'-'A'; - break; - case 0x8: - aux_note.command='X'-'A'; - break; - case 0x9: - aux_note.command='O'-'A'; - break; - case 0xa: - aux_note.command='D'-'A'; - break; - case 0xb: - aux_note.command='B'-'A'; - break; - case 0xc: - //printf("XM Import: Warning! effect C (set volume) not implemented!\n"); - break; - case 0xd: - aux_note.command='C'-'A'; - break; - - case 0xe: /* Extended effects */ - - aux_note.command='S'-'A'; - switch(aux_note.parameter>>4) { - case 0x1: /* XM fine porta up */ - if (!(aux_note.parameter&0xF)) { aux_note.command=CPNote::EMPTY; aux_note.parameter=0; break; } - aux_note.command='F'-'A'; - aux_note.parameter=0xF0|(aux_note.parameter&0xF); - break; - case 0x2: /* XM fine porta down */ - if (!(aux_note.parameter&0xF)) { aux_note.command=CPNote::EMPTY; aux_note.parameter=0; break; } - aux_note.command='E'-'A'; - aux_note.parameter=0xF0|(aux_note.parameter&0xF); - break; - case 0xa: /* XM fine volume up */ - if (!(aux_note.parameter&0xF)) { aux_note.command=CPNote::EMPTY; aux_note.parameter=0; break; } - aux_note.command='D'-'A'; - aux_note.parameter=0x0F|((aux_note.parameter&0xF)<<4); - - break; - case 0xb: /* XM fine volume down */ - if (!(aux_note.parameter&0xF)) { aux_note.command=CPNote::EMPTY; aux_note.parameter=0; break; } - aux_note.command='D'-'A'; - aux_note.parameter=0xF0|(aux_note.parameter&0xF); - - break; - case 0x9: /* XM fine volume down */ - if (!(aux_note.parameter&0xF)) { aux_note.command=CPNote::EMPTY; aux_note.parameter=0; break; } - aux_note.command='Q'-'A'; - aux_note.parameter=0x00|(aux_note.parameter&0xF); - break; - - case 0xc: //notecut - - aux_note.parameter=0xC0|(aux_note.parameter&0xF); - break; - - case 0xd: //notedelay - - aux_note.parameter=0xD0|(aux_note.parameter&0xF); - break; - - case 0xe: //patterndelay - - aux_note.parameter=0xE0|(aux_note.parameter&0xF); - break; - } - - break; - case 0xf: - if (aux_note.parameter<32) { - aux_note.command='A'-'A'; - } else { - aux_note.command='T'-'A'; - } - break; - case 'G'-55: - aux_note.command='V'-'A'; - break; - case 'H'-55: - aux_note.command='W'-'A'; - break; - case 'K'-55: - if (aux_note.note!=CPNote::EMPTY) break; - aux_note.note=CPNote::OFF; - break; - case 'P'-55: - aux_note.command='P'-'A'; - break; - case 'R'-55: - aux_note.command='Q'-'A'; - break; - case 'T'-55: - aux_note.command='I'-'A'; - break; - default: { - - aux_note.command=CPNote::EMPTY; - } - } - - - } - - song->get_pattern( i)->set_note( k,j,aux_note ); - } - } - - /************************************** - LOAD INSTRUMENTS! - ***************************************/ - - for (int i=0;i<header.instruments_used;i++) { - - - uint32_t aux; - int sampnum; - - CPInstrument &instrument=*song->get_instrument(i); - uint32_t cpos=file->get_pos(); - //printf("pos is %i\n",cpos); - - - -/* +4 */ uint32_t hsize=file->get_dword(); //header length - - char instrname[23]; - instrname[22]=0; - - file->get_byte_array((uint8_t*)instrname,22); -//XM_LOAD_DEBUG printf("name is %s\n",instrname); - -/* +27 */ aux=file->get_byte(); //byte that must be ignored -//XM_LOAD_DEBUG printf("header size is %i\n",hsize); - -/* +29 */ sampnum=file->get_word(); - -//XM_LOAD_DEBUG printf("samples %i\n",sampnum); - - - instrument.set_name( instrname ); -// printf("Header Len: %i, CPInstrument %i, %i samples , name: s,\n",hsize,i,sampnum,instrname); - - if (sampnum==0) { - //aux=file->get_dword(); //Why is this for? -- for nothing, skipped - if (hsize) { - - file->seek( cpos+hsize ); //skip header if size has been specified - } - continue; - } - -/* +33 */ file->get_dword(); - - if (Error result=load_instrument_internal(&instrument,false,cpos,hsize,sampnum)) { - - CP_PRINTERR("Error loading instrument"); - file->close(); - return result; - } - - } -// - file->close(); - return FILE_OK; -} - -CPLoader::Error CPLoader_XM::load_instrument_internal(CPInstrument *p_instr,bool p_xi,int p_cpos, int p_hsize, int p_sampnum) { - - int sampnum; - uint32_t aux; - uint8_t notenumb[96]; - uint16_t panenv[24],volenv[24]; - int volpoints,panpoints; - int vol_loop_begin,vol_loop_end,vol_sustain_loop; - int pan_loop_begin,pan_loop_end,pan_sustain_loop; - char instrname[23]; - int sample_index[16]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; //-1 means no index! - - instrname[22]=0; - - -/* +129 */ file->get_byte_array((uint8_t*)notenumb,96); - for (int j=0;j<24;j++) { - volenv[j]=file->get_word(); - } - for (int j=0;j<24;j++) { - panenv[j]=file->get_word(); - } - -/* +177 */ -/* +225 */ -/* +226 */ volpoints=file->get_byte(); -/* +227 */ panpoints=file->get_byte(); -/* +230 */ vol_sustain_loop=file->get_byte(); -/* +228 */ vol_loop_begin=file->get_byte(); -/* +229 */ vol_loop_end=file->get_byte(); - -//XM_LOAD_DEBUG printf("1- volpoints: %i, panpoints: %i, susloop: %i, loop begin: %i, loop end %i\n",volpoints,panpoints,vol_sustain_loop,vol_loop_begin,vol_loop_end); - pan_sustain_loop=file->get_byte(); -/* +231 */ pan_loop_begin=file->get_byte(); -/* +232 */ pan_loop_end=file->get_byte(); - - - -/* +234 */ aux=file->get_byte(); - p_instr->get_volume_envelope()->reset(); - p_instr->get_volume_envelope()->set_enabled(aux&1); - p_instr->get_volume_envelope()->set_sustain_loop_enabled((aux&2)?true:false); - p_instr->get_volume_envelope()->set_loop_enabled((aux&4)?true:false); -/* +235 */ aux=file->get_byte(); - p_instr->get_pan_envelope()->reset(); - p_instr->get_pan_envelope()->set_enabled(aux&1); - p_instr->get_pan_envelope()->set_sustain_loop_enabled((aux&2)?true:false); - p_instr->get_pan_envelope()->set_loop_enabled((aux&4)?true:false); - -/* +239 */ aux=file->get_dword(); // sadly, cant use those -/* +241 */ p_instr->set_volume_fadeout( file->get_word() >> 4 ); -/* +243 */ aux=file->get_word(); // reserved! - - - - for (int j=0;j<volpoints;j++) { - int ofs=volenv[j*2]; - int val=volenv[j*2+1]; - p_instr->get_volume_envelope()->add_position(ofs,val); - - } - - //make sure minimum is 2 - while (p_instr->get_volume_envelope()->get_node_count()<2) { - - p_instr->get_volume_envelope()->add_position( p_instr->get_volume_envelope()->get_node_count()*20,64 ); - } - - for (int j=0;j<panpoints;j++) { - int ofs=panenv[j*2]; - int val=panenv[j*2+1]; - p_instr->get_pan_envelope()->add_position(ofs,val-32); - } - - //make sure minimum is 2 - while (p_instr->get_pan_envelope()->get_node_count()<2) { - - p_instr->get_pan_envelope()->add_position( p_instr->get_pan_envelope()->get_node_count()*20,0 ); - } - - - p_instr->get_volume_envelope()->set_loop_begin(vol_loop_begin); - p_instr->get_volume_envelope()->set_loop_end(vol_loop_end); - p_instr->get_volume_envelope()->set_sustain_loop_end(vol_sustain_loop); - p_instr->get_volume_envelope()->set_sustain_loop_begin(vol_sustain_loop); - p_instr->get_pan_envelope()->set_loop_begin(pan_loop_begin); - p_instr->get_pan_envelope()->set_loop_end(pan_loop_end); - p_instr->get_pan_envelope()->set_sustain_loop_end(pan_sustain_loop); - p_instr->get_pan_envelope()->set_sustain_loop_begin(pan_sustain_loop); - - - if (!p_xi) { - - if ((file->get_pos()-p_cpos)<p_hsize) { - - uint8_t junkbuster[500]; - - //printf("extra junk XM instrument in header! hsize is %i, extra junk: %i\n",p_hsize,(file->get_pos()-p_cpos)); - //printf("extra: %i\n",p_hsize-(file->get_pos()-p_cpos)); - file->get_byte_array((uint8_t*)junkbuster,p_hsize-(file->get_pos()-p_cpos)); - } - - sampnum=p_sampnum; - } else { - - uint8_t junkbuster[500]; - file->get_byte_array((uint8_t*)junkbuster,20); //14 bytes? - - sampnum=file->get_word(); - - } - - - CPSampleManager *sm=CPSampleManager::get_singleton(); - - /*SAMPLE!!*/ - - for (int j=0;j<sampnum;j++) { - - if (j>16) ABORT_LOAD; - - - int s_idx=-1; - for (int s=0;s<CPSong::MAX_SAMPLES;s++) { - - if (song->get_sample(s)->get_sample_data().is_null()) { - //empty sample! - s_idx=s; - break; - } - } - - if (s_idx==-1) ABORT_LOAD; - //printf("free sample: %i\n",s_idx); - - - CPSample& sample=*song->get_sample(s_idx); - - int sample_size=file->get_dword(); - int tmp_loop_begin=file->get_dword(); - - int tmp_loop_end=file->get_dword(); - - sample.set_default_volume(file->get_byte()); - - uint8_t ftb=file->get_byte(); - int8_t *fts=(int8_t*)&ftb; - int finetune=*fts; - uint32_t flags=file->get_byte(); - - if (flags&16) { // is 16 bits.. at flag 16.. fun :) - - tmp_loop_end/=2; - tmp_loop_begin/=2; - sample_size/=2; - } - - - CPSample_ID sample_data=sm->create( flags&16, false, sample_size ); - - sample.set_sample_data(sample_data); - sm->set_loop_begin(sample_data,tmp_loop_begin); - sm->set_loop_end(sample_data,tmp_loop_end+tmp_loop_begin); - - sm->set_loop_type( sample_data, (flags&3)?( (flags&2) ? CP_LOOP_BIDI : CP_LOOP_FORWARD ):CP_LOOP_NONE ); - - - - sample.set_pan_enabled(true); - sample.set_pan(file->get_byte()*64/255); - uint8_t noteb=file->get_byte(); - int8_t *notes=(int8_t*)¬eb; - int note_offset=*notes; - note_offset+=48; - //note_offset+=60; - - - - //int linear_period=10*12*16*4 - (note_offset)*16*4 - finetune/2; - //int freq=(int)(8363*pow(2.0,(double)(6*12*16*4 - linear_period) / (double)(12*16*4))); - - //sm->set_c5_freq( sample_data, freq); - sm->set_c5_freq( sample_data, CPTables::get_linear_frequency(CPTables::get_linear_period(note_offset<<1,finetune)) ); - //printf("NOTE %i,fine %i\n",note_offset,finetune); - - char auxb; - auxb=file->get_byte(); //reserved? - file->get_byte_array((uint8_t*)instrname,22); - sample.set_name(instrname); - - sample_index[j]=s_idx; - } - - /*SAMPLE __DATA__!!*/ - - for (int j=0;j<sampnum;j++) { - - if (sample_index[j]==-1) continue; - - CPSample *sample=song->get_sample(sample_index[j]); - CPSample_ID sid=sample->get_sample_data(); - - sm->lock_data(sid); - - void*dataptr=sm->get_data(sid); - - if (sm->is_16bits( sid)) { - - int16_t old=0; - - - for (int k=0;k<sm->get_size(sid);k++) { - - int16_t newsample; - int16_t sampleval=file->get_word(); - newsample=sampleval+old; - old=newsample; - - ((int16_t*)dataptr)[k]=newsample; - //sm->set_data( sid, k, newsample ); - } - } else { - - int8_t old=0; - - - for (int k=0;k<sm->get_size(sid);k++) { - - int8_t newsample; - int8_t sampleval=file->get_byte(); - newsample=sampleval+old; - old=newsample; - - ((int8_t*)dataptr)[k]=newsample; - - //sm->set_data( sid, k, (int16_t)newsample << 8 ); - - } - } - - sm->unlock_data(sid); - - } - - for (int j=0;j<96;j++) { - - int val=notenumb[j]; - if ((val<0) || (val>15)) continue; - else val=sample_index[val]; - if (val==-1) continue; - p_instr->set_sample_number( 12+j,val ); - } - - - return FILE_OK; -} - - - -CPLoader::Error CPLoader_XM::load_sample(const char *p_file,CPSample *p_sample) { - - return FILE_UNRECOGNIZED; -} - - -/* Compute CPInstrument Info */ -CPLoader::Error CPLoader_XM::load_instrument(const char *p_file,CPSong *p_song,int p_instr_idx) { - - if ( file->open(p_file,CPFileAccessWrapper::READ) ) return FILE_CANNOT_OPEN; - //int i; - song=p_song; - CPInstrument& instr=*p_song->get_instrument( p_instr_idx ); - int aux; - - - char buffer[500]; - file->get_byte_array((uint8_t*)buffer,0x15); - buffer[8]=0; - if ( buffer[0]!='E' || - buffer[1]!='x' || - buffer[2]!='t' || - buffer[3]!='e' || - buffer[4]!='n' || - buffer[5]!='d' || - buffer[6]!='e' || - buffer[7]!='d') { - file->close(); - return FILE_UNRECOGNIZED; - } - - file->get_byte_array((uint8_t*)buffer,0x16); - buffer[0x16]=0; - instr.set_name(buffer); - aux=file->get_byte(); //says ignore ti - /*if(aux!=0x1a) { I'm not sure. this is supposed to be ignored... - - file->close(); - return FILE_UNRECOGNIZED; - } */ - - file->get_byte_array((uint8_t*)buffer,0x14); //somethingaboutthename - aux=file->get_word(); //version or blahblah - - if (load_instrument_internal(&instr,true,0,0)) { - - file->close(); - return FILE_CORRUPTED; - } - - file->close(); //ook, we got it.. - - - return FILE_OK; - -} - - - -CPLoader_XM::CPLoader_XM(CPFileAccessWrapper *p_file){ - - file=p_file; -} -CPLoader_XM::~CPLoader_XM(){ -} - diff --git a/modules/chibi/cp_loader_xm.h b/modules/chibi/cp_loader_xm.h deleted file mode 100644 index 0889569b3..000000000 --- a/modules/chibi/cp_loader_xm.h +++ /dev/null @@ -1,89 +0,0 @@ -/*************************************************************************/ -/* cp_loader_xm.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef CP_LOADER_XM_H -#define CP_LOADER_XM_H - -#include "cp_loader.h" - - -/** - *@author red - */ - - - - -class CPLoader_XM : public CPLoader { - - - struct XM_Header { - - uint8_t idtext[18]; - uint8_t songname[21]; - uint8_t hex1a; // ? - uint8_t trackername[21]; - uint16_t version; - uint32_t headersize; //from here - - uint16_t songlength; //pattern ordertable - uint16_t restart_pos; - uint16_t channels_used; - uint16_t patterns_used; - uint16_t instruments_used; - uint16_t use_linear_freq; - uint16_t tempo; - uint16_t speed; - uint8_t orderlist[256]; - - } header; - - CPFileAccessWrapper *file; - - Error load_instrument_internal(CPInstrument *pint,bool p_xi,int p_cpos, int p_hsize, int p_sampnumb=-1); - CPSong *song; - -public: - - bool can_load_song() { return true; } - bool can_load_sample() { return false; } - bool can_load_instrument() { return true; } - - Error load_song(const char *p_file,CPSong *p_song,bool p_sampleset); - Error load_sample(const char *p_file,CPSample *p_sample); - Error load_instrument(const char *p_file,CPSong *p_song,int p_instr_idx); - - - CPLoader_XM(CPFileAccessWrapper *p_file); - ~CPLoader_XM(); -}; - - - -#endif diff --git a/modules/chibi/cp_mixer.h b/modules/chibi/cp_mixer.h deleted file mode 100644 index d8564bae0..000000000 --- a/modules/chibi/cp_mixer.h +++ /dev/null @@ -1,115 +0,0 @@ -/*************************************************************************/ -/* cp_mixer.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef CP_MIXER_H -#define CP_MIXER_H - -#include "cp_sample_defs.h" - -/**Abstract base class representing a mixer - *@author Juan Linietsky - */ - - -/****************************** - mixer.h - ---------- - -Abstract base class for the mixer. -This is what the player uses to setup -voices and stuff.. this way -it can be abstracted to hardware -devices or other stuff.. -********************************/ - -class CPSample_ID; /* need this */ - -class CPMixer { -public: - - enum { - - FREQUENCY_BITS=8 - - }; - - enum ReverbMode { - REVERB_MODE_ROOM, - REVERB_MODE_STUDIO_SMALL, - REVERB_MODE_STUDIO_MEDIUM, - REVERB_MODE_STUDIO_LARGE, - REVERB_MODE_HALL, - REVERB_MODE_SPACE_ECHO, - REVERB_MODE_ECHO, - REVERB_MODE_DELAY, - REVERB_MODE_HALF_ECHO - }; - - /* Callback */ - - virtual void set_callback_interval(int p_interval_us)=0; //in usecs, for tracker it's 2500000/tempo - virtual void set_callback(void (*p_callback)(void*),void *p_userdata)=0; - - /* Voice Control */ - - virtual void setup_voice(int p_voice_index,CPSample_ID p_sample_id,int32_t p_start_index) =0; - virtual void stop_voice(int p_voice_index) =0; - virtual void set_voice_frequency(int p_voice_index,int32_t p_freq) =0; //in freq*FREQUENCY_BITS - virtual void set_voice_panning(int p_voice_index,int p_pan) =0; - virtual void set_voice_volume(int p_voice_index,int p_vol) =0; - virtual void set_voice_filter(int p_filter,bool p_enabled,uint8_t p_cutoff, uint8_t p_resonance )=0; - virtual void set_voice_reverb_send(int p_voice_index,int p_reverb)=0; - virtual void set_voice_chorus_send(int p_voice_index,int p_chorus)=0; /* 0 - 255 */ - - virtual void set_reverb_mode(ReverbMode p_mode)=0; - virtual void set_chorus_params(unsigned int p_delay_ms,unsigned int p_separation_ms,unsigned int p_depth_ms10,unsigned int p_speed_hz10)=0; - - - /* Info retrieving */ - - virtual int32_t get_voice_sample_pos_index(int p_voice_index) =0; - virtual int get_voice_panning(int p_voice_index) =0; - virtual int get_voice_volume(int p_voice_index) =0; - virtual CPSample_ID get_voice_sample_id(int p_voice_index) =0; - virtual bool is_voice_active(int p_voice_index) =0; - virtual int get_active_voice_count()=0; - virtual int get_total_voice_count()=0; - - - virtual uint32_t get_mix_frequency()=0; //if mixer is not software, return 0 - - /* Methods below only work with software mixers, meant for software-based sound drivers, hardware mixers ignore them */ - virtual int32_t process(int32_t p_frames)=0; /* Call this to process N frames, returns how much it was processed */ - virtual int32_t *get_mixdown_buffer_ptr()=0; /* retrieve what was mixed */ - virtual void set_mix_frequency(int32_t p_mix_frequency)=0; - - virtual ~CPMixer() {} -}; - -#endif diff --git a/modules/chibi/cp_note.h b/modules/chibi/cp_note.h deleted file mode 100644 index f9a3ef39f..000000000 --- a/modules/chibi/cp_note.h +++ /dev/null @@ -1,102 +0,0 @@ -/*************************************************************************/ -/* cp_note.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef CP_NOTE_H -#define CP_NOTE_H - -#include "cp_config.h" - -struct CPNote { - - enum { - - NOTES=120, - OFF=254, - CUT=253, - EMPTY=255, - SCRIPT=252, - }; - - - uint8_t note; - uint8_t instrument; - uint8_t volume; - uint8_t command; - uint8_t parameter; - unsigned int script_source_sign; - bool cloned; - - void clear() { - - note=EMPTY; - instrument=EMPTY; - volume=EMPTY; - command=EMPTY; - parameter=0; - script_source_sign='\0'; - cloned=false; - } - - void raise() { - - if (note<(NOTES-1)) - note++; - else if (note==SCRIPT && parameter<0xFF) - parameter++; - } - - void lower() { - - if ((note>0) && (note<NOTES)) - note--; - else if (note==SCRIPT && parameter>0) - parameter--; - - } - - bool operator== (const CPNote &rvalue) { - - return ( - (note==rvalue.note) && - (instrument==rvalue.instrument) && - (volume==rvalue.volume) && - (command==rvalue.command) && - (parameter==rvalue.parameter) - ); - } - - bool is_empty() const { return (note==EMPTY && instrument==EMPTY && volume==EMPTY && command==EMPTY && parameter==0 && !cloned); } - CPNote() { - - clear(); - } -}; - - -#endif - diff --git a/modules/chibi/cp_order.h b/modules/chibi/cp_order.h deleted file mode 100644 index 8df67df40..000000000 --- a/modules/chibi/cp_order.h +++ /dev/null @@ -1,43 +0,0 @@ -/*************************************************************************/ -/* cp_order.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef CP_ORDER_H -#define CP_ORDER_H - - -#include "cp_config.h" - -enum CPOrderType { - CP_ORDER_NONE=255, - CP_ORDER_BREAK=254 -}; - -typedef uint8_t CPOrder; - -#endif - diff --git a/modules/chibi/cp_pattern.cpp b/modules/chibi/cp_pattern.cpp deleted file mode 100644 index 8671b6247..000000000 --- a/modules/chibi/cp_pattern.cpp +++ /dev/null @@ -1,574 +0,0 @@ -/*************************************************************************/ -/* cp_pattern.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "cp_pattern.h" - -void CPPattern::clear() { - - if (event_count>0) { - - - CP_FREE(events); - events=NULL; - event_count=0; - } - - length=DEFAULT_LEN; - -} - - -bool CPPattern::resize_event_list_to(uint32_t p_events) { - - - //Module is slow in some cpus, so this should be fast enough - uint32_t new_size=((p_events-1)&(~((1<<RESIZE_EVERY_BITS)-1)))+(1<<RESIZE_EVERY_BITS); - - CP_ERR_COND_V(new_size<p_events,true); //bugARM_INFO - - if (event_count==0 && new_size==0) - return false; //nothing to do - - if (event_count==0) { - - events=(Event*)CP_ALLOC( new_size*sizeof(Event) ); - - } else if (new_size==0) { - - CP_FREE(events); - events=NULL; - } else { - - CP_ERR_COND_V(events==NULL,true); - events=(Event*)CP_REALLOC(events, new_size*sizeof(Event)); - - } - - event_count=p_events; - - return false; -} - - -int32_t CPPattern::get_event_pos(uint16_t p_target_pos) { - - - if (event_count==0) - return -1; - - int low = 0; - int high = event_count -1; - int middle; - - while( low <= high ) - { - middle = ( low + high ) / 2; - - if( p_target_pos == events[middle].pos ) { //match - break; - } else if( p_target_pos < events[middle].pos ) - high = middle - 1; //search low end of array - else - low = middle + 1; //search high end of array - } - - /* adapt so we are behind 2 */ - - if (events[middle].pos<p_target_pos) - middle++; - return middle; - - /* Linear search for now */ - - /* - int32_t pos_idx=0; - - for (;pos_idx<event_count;pos_idx++) { - - if (event_list[pos_idx].pos>=p_target_pos) - break; - - } */ - - //return pos_idx; -} - -bool CPPattern::erase_event_at_pos(uint16_t p_pos) { - - if (event_count==0) - return false; - - - - Event *event_list=events; - - int32_t pos_idx = get_event_pos(p_pos); - if (pos_idx==-1) { - CP_ERR_COND_V(pos_idx==-1,true); - } - - if (pos_idx==event_count || event_list[pos_idx].pos!=p_pos) { - /* Nothing to Erase */ - return false; - } - - for (int32_t i=pos_idx;i<(event_count-1);i++) { - - event_list[i]=event_list[i+1]; - } - - - resize_event_list_to(event_count-1); - - return false; -} - -bool CPPattern::set_note(uint8_t p_column, uint16_t p_row,const CPNote& p_note) { - - CP_ERR_COND_V(p_column>=WIDTH,true); - CP_ERR_COND_V(p_row>=length,true); - - int32_t new_pos; - uint16_t target_pos=p_row*WIDTH+p_column; - - - - if (p_note.is_empty()) { - bool res=erase_event_at_pos(target_pos); - - return res;; - } - - Event *event_list=0; - - if (event_count==0) { - /* If no events, create the first */ - - if (resize_event_list_to(1)) { - - CP_PRINTERR("Can't resize event list to 1"); - return true; - } - - event_list=events; - if (event_list==0) { - - - CP_PRINTERR("Can't get event list"); - return true; - } - - new_pos=0; - - } else { - /* Prepare to add */ - - event_list=events; - if (event_list==0) { - - - CP_PRINTERR("Can't get event list"); - return true; - } - - int32_t pos_idx = get_event_pos(target_pos); - - if (pos_idx==-1) { - - - CP_PRINTERR("Can't find add position"); - return true; - } - - - if (pos_idx==event_count || event_list[pos_idx].pos!=target_pos) { - /* If the note being modified didnt exist, then we add it */ - - //resize, and return if out of mem - if (resize_event_list_to( event_count+1)) { - - - CP_PRINTERR("Can't resize event list"); - return true; - } - event_list=events; - if (event_list==0) { - - - CP_PRINTERR("Can't get event list"); - return true; - } - - //make room for new pos, this wont do a thing if pos_idx was ==event_count - for(int32_t i=(event_count-1);i>pos_idx;i--) { - event_list[i]=event_list[i-1]; - - } - - } /* Else it means that position is taken, so we just modify it! */ - - - new_pos=pos_idx; - } - - event_list[new_pos].pos=target_pos; - event_list[new_pos].note=p_note.note; - event_list[new_pos].instrument=p_note.instrument; - event_list[new_pos].volume=p_note.volume; - event_list[new_pos].command=p_note.command; - event_list[new_pos].parameter=p_note.parameter; - event_list[new_pos].script_source_sign=p_note.script_source_sign; - event_list[new_pos].cloned=p_note.cloned; - - - - - return false; - -} -CPNote CPPattern::get_note(uint8_t p_column,uint16_t p_row) { - - if (p_column==CPNote::EMPTY) return CPNote(); - - CP_ERR_COND_V(p_column>=WIDTH,CPNote()); - CP_ERR_COND_V(p_row>=length,CPNote()); - - if (event_count==0) - return CPNote(); - - - Event *event_list=events; - - CP_ERR_COND_V(event_list==0,CPNote()); - - uint16_t target_pos=p_row*WIDTH+p_column; - int32_t pos_idx = get_event_pos(target_pos); - if (pos_idx==-1) { - - CP_PRINTERR("Can't find event pos"); - return CPNote(); - } - - if (pos_idx>=event_count || event_list[pos_idx].pos!=target_pos) { - /* no note found */ - - return CPNote(); - } - - CPNote n; - n.note=event_list[pos_idx].note; - n.instrument=event_list[pos_idx].instrument; - n.volume=event_list[pos_idx].volume; - n.command=event_list[pos_idx].command; - n.parameter=event_list[pos_idx].parameter; - n.script_source_sign=event_list[pos_idx].script_source_sign; - n.cloned=event_list[pos_idx].cloned; - - - return n; - -} - -CPNote CPPattern::get_transformed_script_note(uint8_t p_column,uint16_t p_row ) { - - CPNote n = get_note( p_column, p_row ); - - // get source channel and note - - int channel = get_scripted_note_target_channel( p_column, p_row ); - CPNote src_n = get_note( channel, 0 ); - - if ( src_n.note == CPNote::SCRIPT ) return CPNote(); - - script_transform_note( src_n, n ); - - return src_n; - -} - -int CPPattern::get_scripted_note_target_channel(uint8_t p_column, uint16_t p_row) { - - CPNote n = get_note( p_column, p_row ); - - if ( n.note != CPNote::SCRIPT ) return CPNote::EMPTY; - - int channel = n.instrument; - - if ( n.script_source_sign == '\0' ) { - - if ( channel < 0 || channel >= CPPattern::WIDTH ) return CPNote::EMPTY; - - } else { - - channel = p_column + ( ( n.script_source_sign=='+') ? 1 : -1 ) * (channel+1); - if ( channel < 0 || channel >= CPPattern::WIDTH ) return CPNote::EMPTY; - - } - - return channel; -} - -void CPPattern::scripted_clone(uint8_t p_column, uint16_t p_row) { - - int channel = get_scripted_note_target_channel( p_column, p_row ); - int src_row = 1; - CPNote script_n = get_note( p_column, p_row ); - - for ( int row = p_row+1; row < length; ++row ) { - - CPNote src_n = get_note( channel, src_row ); - CPNote target_n = get_note( p_column, row ); - - if ( target_n.note != CPNote::SCRIPT ) { - if ( src_n.note == CPNote::SCRIPT ) { - src_n = CPNote(); - channel = CPNote::EMPTY; - } - - script_transform_note( src_n, script_n ); - - src_n.cloned = true; - set_note( p_column, row, src_n ); - - } else { - - return; - - } - - src_row++; - } - -} - -void CPPattern::scripted_clone_remove(uint8_t p_column, uint16_t p_row) { - - if ( get_note( p_column, p_row ).cloned ) - set_note( p_column, p_row, CPNote() ); - - for ( int row = p_row+1; row < length; ++row ) { - - CPNote target_n = get_note( p_column, row ); - - if ( target_n.note != CPNote::SCRIPT ) { - - set_note( p_column, row, CPNote() ); - - } else { - - return; - - } - - } - -} - -void CPPattern::script_transform_note(CPNote& n, const CPNote& p_note) { - - // set instrument - - if ( n.note < CPNote::NOTES && p_note.volume != CPNote::EMPTY ) { - - n.instrument = p_note.volume; - - } - - // transpose - - if ( n.note < CPNote::NOTES && p_note.command != CPNote::EMPTY ) { - - int transpose = ( p_note.parameter & 0xF ) + ( p_note.parameter / 0x10 ) * 12; - - if ( p_note.command == '^' ) { - - if ( n.note >= CPNote::NOTES-transpose ) - n.note = CPNote::NOTES-1; - else - n.note += transpose; - - } else if ( p_note.command == 'v' ) { - - if ( n.note <= transpose ) - n.note = 0; - else - n.note -= transpose; - - } - } - -} - -bool CPPattern::update_scripted_clones_sourcing_channel( int channel ) { - - bool updated = false; - - for ( int x = 0; x < WIDTH; ++x ) { - - for (int y = 0; y < length; ++y ) { - - if ( channel == get_scripted_note_target_channel( x, y ) ) { - - scripted_clone( x, y ); - updated = true; - } - - } - - } - - return updated; -} - -void CPPattern::set_length(uint16_t p_rows) { - - - - if (event_count==0) { - - if (p_rows>=MIN_ROWS) - length=p_rows; - - - return; - - } - - if (p_rows<MIN_ROWS) { - - return; - } - - if (p_rows<length) { - - Event* event_list=events; - if (event_list==0) { - - CP_PRINTERR("get_event_list() Failed"); - return; - } - - - uint16_t target_pos=p_rows*WIDTH; - int32_t pos_idx = get_event_pos(target_pos); - - - if (pos_idx==-1) { - - CP_ERR_COND(pos_idx==-1); - } - - if (resize_event_list_to(pos_idx)) { - - CP_PRINTERR("resize_event_list_to(pos_idx) Failed"); - return; - } - - } - - length=p_rows; - - -} -#if 0 -void CPPattern::copy_to(CPPattern *p_pattern) const { - - - - - p_pattern->clear(); - p_pattern->length=length; - - - if (!event_count) - return; - - - - int bufsiz=MemPool_Wrapper::get_singleton()->get_mem_size( mem_handle ); - MemPool_Handle aux_mem_handle=MemPool_Wrapper::get_singleton()->alloc_mem( bufsiz ); - - if (aux_mem_handle.is_null()) { - - CP_PRINTERR("own handle is null"); - - return; - } - - - if (MemPool_Wrapper::get_singleton()->lock_mem(aux_mem_handle)) { - CP_PRINTERR("Unable to lock aux new handle"); - - return; - - } - - if (MemPool_Wrapper::get_singleton()->lock_mem(mem_handle)) { - - CP_PRINTERR("Unable to lock own handle"); - - return; - } - - uint8_t* srcuint8_tt8_t*)MemPool_Wrapper::get_singleton()->get_mem(mem_handle); - uint8_t* dstuint8_tt8_t*)MemPool_Wrapper::get_singleton()->get_mem(aux_mem_handle); - - for (int i=0;i<bufsiz;i++) - dst[i]=src[i]; - - MemPool_Wrapper::get_singleton()->unlock_mem(mem_handle); - MemPool_Wrapper::get_singleton()->unlock_mem(aux_mem_handle); - - p_pattern->mem_handle=aux_mem_handle; - p_pattern->event_count=event_count; - - -} -#endif -uint16_t CPPattern::get_length() { - - - return length; -} -CPPattern::CPPattern() { - - - length=DEFAULT_LEN; - event_count=0; - clear(); - -} -bool CPPattern::is_empty() { - - return events==NULL; -} - -CPPattern::~CPPattern() { - - clear(); -} diff --git a/modules/chibi/cp_pattern.h b/modules/chibi/cp_pattern.h deleted file mode 100644 index fc3b03252..000000000 --- a/modules/chibi/cp_pattern.h +++ /dev/null @@ -1,94 +0,0 @@ -/*************************************************************************/ -/* cp_pattern.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef CP_PATTERN_H -#define CP_PATTERN_H - -#include "cp_note.h" - -class CPPattern { -public: - - - enum { - WIDTH=64, - DEFAULT_LEN=64, - RESIZE_EVERY_BITS=4, - MIN_ROWS=1, //otherwise clipboard wont work - MAX_LEN=256 - - }; - -private: - struct Event { - - uint16_t pos; //column*WIDTH+row - uint8_t note; - uint8_t instrument; - uint8_t volume; - uint8_t command; - uint8_t parameter; - unsigned int script_source_sign; - bool cloned; - }; - - uint16_t length; - uint32_t event_count; - Event* events; - - int32_t get_event_pos(uint16_t p_target_pos); - bool erase_event_at_pos(uint16_t p_pos); - - bool resize_event_list_to(uint32_t p_events); - - void operator=(const CPPattern& p_pattern); //no operator= -public: - - bool is_empty(); - void clear(); - - bool set_note(uint8_t p_column, uint16_t p_row,const CPNote& p_note); //true if no more memory - CPNote get_note(uint8_t p_column,uint16_t p_row); - - CPNote get_transformed_script_note(uint8_t p_column, uint16_t p_row); - int get_scripted_note_target_channel(uint8_t p_column, uint16_t p_row); - void scripted_clone(uint8_t p_column, uint16_t p_row); - void scripted_clone_remove(uint8_t p_column, uint16_t p_row); - void script_transform_note(CPNote& n, const CPNote& p_note); - bool update_scripted_clones_sourcing_channel(int channel); - - //void copy_to(CPPattern *p_pattern) const; - void set_length(uint16_t p_rows); - uint16_t get_length(); - CPPattern(); - ~CPPattern(); - - -}; - -#endif diff --git a/modules/chibi/cp_player_data.cpp b/modules/chibi/cp_player_data.cpp deleted file mode 100644 index c8cbfbd06..000000000 --- a/modules/chibi/cp_player_data.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/*************************************************************************/ -/* cp_player_data.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "cp_player_data.h" -#include <stdio.h> - - -CPPlayer::CPPlayer(CPMixer *p_mixer,CPSong *p_song){ - - song=p_song; - mixer=p_mixer; - control.max_voices=p_mixer->get_total_voice_count()-1; //leave one for the sample - control.force_no_nna=false; - control.external_vibrato=false; - control.filters=true; - control.random_seed=128364; //anything - control.play_mode=0; - set_virtual_channels(p_mixer->get_total_voice_count()); - mixer->set_callback( &CPPlayer::callback_function, this ); - - reset(); -} -CPPlayer::~CPPlayer(){ -} - -void CPPlayer::set_virtual_channels(int p_amount) { - - if (p_amount<1) return; - if (p_amount>mixer->get_total_voice_count()) - return; - - control.max_voices=p_amount; - -} - - -void CPPlayer::callback_function(void *p_userdata) { - - CPPlayer*pd=(CPPlayer*)p_userdata; - pd->process_tick(); - -} - -void CPPlayer::process_tick() { - - handle_tick(); - mixer->set_callback_interval( 2500000/control.tempo ); - song_usecs+=2500000/control.tempo; -} - -void CPPlayer::reset() { - - if ( mixer==NULL ) return ; - if ( song==NULL ) return ; - - int i; - - for (i=0;i<control.max_voices;i++) { - - voice[i].reset(); - mixer->stop_voice(i); - } - - for (i=0;i<CPPattern::WIDTH;i++) { - - control.channel[i].reset(); - control.channel[i].channel_volume=song->get_channel_volume(i); - control.channel[i].channel_panning=((int)song->get_channel_pan( i)*PAN_RIGHT/64); - if (song->is_channel_surround(i)) - control.channel[i].channel_panning=PAN_SURROUND; - control.channel[i].mute=song->is_channel_mute( i ); - control.channel[i].chorus_send=song->get_channel_chorus(i)*0xFF/64; - control.channel[i].reverb_send=song->get_channel_reverb(i)*0xFF/64; - } - - - control.speed=song->get_speed(); - control.tempo=song->get_tempo(); - control.global_volume=song->get_global_volume(); - - control.position.current_pattern=0; - control.position.current_row=0; - control.position.current_order=0; - control.position.force_next_order=-1; - control.ticks_counter=control.speed; - control.position.forbid_jump=false; - - song_usecs=0; - -} - -int64_t CPPlayer::get_channel_last_note_time_usec(int p_channel) const { - - CP_FAIL_INDEX_V(p_channel,64,-1); - return control.channel[p_channel].last_event_usecs; - -} - -void CPPlayer::set_channel_global_volume(int p_channel,int p_volume) { - - CP_FAIL_INDEX(p_channel,64); - control.channel[p_channel].channel_global_volume=CLAMP(p_volume,0,255); - -} - -int CPPlayer::get_channel_global_volume(int p_channel) const{ - - CP_FAIL_INDEX_V(p_channel,64,-1); - return control.channel[p_channel].channel_global_volume; - -} - -bool CPPlayer::reached_end_of_song() { - - return control.reached_end; - -} -void CPPlayer::set_force_external_vibratos(bool p_force) { - - control.external_vibrato=p_force; -} -void CPPlayer::set_force_no_nna(bool p_force) { - - control.force_no_nna=p_force; -} diff --git a/modules/chibi/cp_player_data.h b/modules/chibi/cp_player_data.h deleted file mode 100644 index c59df5f0d..000000000 --- a/modules/chibi/cp_player_data.h +++ /dev/null @@ -1,582 +0,0 @@ -/*************************************************************************/ -/* cp_player_data.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef CP_PLAYER_DATA_H -#define CP_PLAYER_DATA_H - -#include "cp_config.h" -#include "cp_song.h" -#include "cp_mixer.h" -#include "cp_tables.h" - -/**CPPlayer Data - *@author Juan Linietsky - */ - -/****************************** - player_data.h - ------------------------ - -The player and its data. -I hope you dont get sick reading this -********************************/ - -//Default pan values - - -class CPPlayer { - - enum { - PAN_SURROUND=512, - PAN_RIGHT=255, - PAN_LEFT=0, - PAN_CENTER=128 - }; - - - CPSong *song; - - CPMixer *mixer; - - struct Filter_Control { - - int32_t it_reso; - int32_t it_cutoff; - int32_t envelope_cutoff; - int32_t final_cutoff; - - void process(); - void set_filter_parameters(int *p_cutoff,uint8_t *p_reso); - - }; - - //tells you if a channel is doing - //noteoff/notekill/notefade/etc - enum { - - END_NOTE_NOTHING=0, - END_NOTE_OFF=1, - END_NOTE_FADE=2, - END_NOTE_KILL=4 - }; - - //Tells you what should a channel restart - enum { - - KICK_NOTHING, - KICK_NOTE, - KICK_NOTEOFF, - KICK_ENVELOPE - }; - - enum { - - MAX_VOICES=256 - }; - - struct Channel_Control; - - struct Voice_Control { - - struct Envelope_Control { - - int pos_index; - int status; - int value; - bool sustain_looping; - bool looping; - bool terminated; - bool active; - bool kill; - - }; - - Filter_Control filter; - uint16_t reverb_send; - uint16_t chorus_send; - - CPInstrument* instrument_ptr; - CPSample* sample_ptr; - -// Sample_Data *sample_data; - - int32_t period; - - int32_t sample_start_index; /* The starting byte index in the sample */ - - bool has_master_channel; - int master_channel_index; - int instruement_index; - - int instrument_index; - int sample_index; - int8_t NNA_type; - - int note_end_flags; - - uint8_t sample; /* which instrument number */ - - int16_t output_volume; /* output volume (vol + sampcol + instvol) */ - int8_t channel_volume; /* channel's "global" volume */ - uint16_t fadeout_volume; /* fading volume rate */ - int32_t total_volume; /* total volume of channel (before global mixings) */ - uint8_t kick; /* if true = sample has to be restarted */ - - uint8_t note; /* the audible note (as heard, direct rep of period) */ - - int16_t panning; /* panning position */ - - uint8_t nna; /* New note action type + master/slave flags */ - uint8_t volflg; /* volume envelope settings */ - uint8_t panflg; /* panning envelope settings */ - uint8_t pitflg; /* pitch envelope settings */ - uint8_t keyoff; /* if true = fade out and stuff */ - int16_t handle; /* which sample-handle */ - int32_t start; /* The start byte index in the sample */ - - /* Below here is info NOT in MP_CONTROL!! */ - //ENVPR venv; - //ENVPR penv; - //ENVPR cenv; - - Envelope_Control volume_envelope_ctrl; - Envelope_Control panning_envelope_ctrl; - Envelope_Control pitch_envelope_ctrl; - - uint16_t auto_vibrato_pos; /* autovibrato pos */ - uint16_t auto_vibrato_sweep_pos; /* autovibrato sweep pos */ - - int16_t masterchn; - uint16_t masterperiod; - - Channel_Control* master_channel; /* index of "master" effects channel */ - - void start_envelope(CPEnvelope *p_envelope,Envelope_Control *p_envelope_ctrl,Envelope_Control *p_from_env); - bool process_envelope(CPEnvelope *p_envelope,Envelope_Control *p_envelope_ctrl); - - uint16_t display_volume; - - Voice_Control() { - - reset(); - } - - void reset(); - void update_info_from_master_channel(); - - - }; - - - struct Channel_Control { - - /* NOTE info */ - uint8_t note; /* the audible note as heard, direct rep of period */ - uint8_t real_note; /* the note that indexes the audible */ - int32_t sample_start_index; /* The starting byte index in the sample */ - uint8_t old_note; - - uint8_t kick; - - Filter_Control filter; - uint16_t reverb_send; - uint16_t chorus_send; - - - int note_end_flags; - - /* INSTRUMENT INFO */ - - CPInstrument* instrument_ptr; - CPSample* sample_ptr; - - uint8_t instrument_index; - uint8_t sample_index; - bool new_instrument; - - /* SAMPLE SPECIFIC INFO */ - int32_t base_speed; /* what finetune to use */ - - /* INSTRUMENT SPECIFIC INFO */ - - int8_t NNA_type; - int8_t duplicate_check_type; - int8_t duplicate_check_action; - - bool volume_envelope_on; - bool panning_envelope_on; - bool pitch_envelope_on; - - bool has_own_period; - - bool row_has_note; - - /* VOLUME COLUMN */ - - int16_t volume; /* amiga volume (0 t/m 64) to play the sample at */ - int16_t aux_volume; - bool has_own_volume; - bool mute; - int16_t random_volume_variation; /* 0-100 - 100 has no effect */ - - /* VOLUME/PAN/PITCH MODIFIERS */ - - int8_t default_volume; // CHANNEL default volume (0-64) - int16_t channel_volume; // CHANNEL current volume //chanvol - current! - int16_t output_volume; /* output volume (vol + sampcol + instvol) //volume */ - int16_t channel_global_volume; - - uint16_t fadeout_volume; /* fading volume rate */ - - int32_t period; /* period to play the sample at */ - - /* PAN */ - - int16_t panning; /* panning position */ - int16_t channel_panning; - int8_t sliding; - - uint16_t aux_period; /* temporary period */ - - - - /* TIMING */ - uint8_t note_delay; /* (used for note delay) */ - - /* Slave Voice Control */ - - Voice_Control *slave_voice; /* Audio Slave of current effects control channel */ - - struct Carry { - - Voice_Control::Envelope_Control vol; - Voice_Control::Envelope_Control pan; - Voice_Control::Envelope_Control pitch; - bool maybe; - - } carry; - - - - uint8_t slave_voice_index; /* Audio Slave of current effects control channel */ - - uint8_t* row; /* row currently playing on this channel */ - - /* effect memory variables */ - - uint8_t current_command; - uint8_t current_parameter; - uint8_t current_volume_command; - uint8_t current_volume_parameter; - uint8_t volcol_volume_slide; - - /* CPSample Offset */ - - int32_t lo_offset; - int32_t hi_offset; - - /* Panbrello waveform */ - uint8_t panbrello_type; /* current panbrello waveform */ - uint8_t panbrello_position; /* current panbrello position */ - int8_t panbrello_speed; /* "" speed */ - uint8_t panbrello_depth; /* "" depth */ - uint8_t panbrello_info; - /* Arpegio */ - - uint8_t arpegio_info; - /* CPPattern Loop */ - - int pattern_loop_position; - int8_t pattern_loop_count; - - /* Vibrato */ - bool doing_vibrato; - int8_t vibrato_position; /* current vibrato position */ - uint8_t vibrato_speed; /* "" speed */ - uint8_t vibrato_depth; /* "" depth */ - uint8_t vibrato_type; - /* Tremor */ - int8_t tremor_position; - uint8_t tremor_speed; /* s3m tremor ontime/offtime */ - uint8_t tremor_depth; - uint8_t tremor_info; - - /* Tremolo */ - int8_t tremolo_position; - uint8_t tremolo_speed; /* s3m tremor ontime/offtime */ - uint8_t tremolo_depth; - uint8_t tremolo_info; - uint8_t tremolo_type; - - /* Retrig */ - int8_t retrig_counter; /* retrig value (0 means don't retrig) */ - uint8_t retrig_speed; /* last used retrig speed */ - uint8_t retrig_volslide; /* last used retrig slide */ - - /* CPSample Offset */ - int32_t sample_offset_hi; /* last used high order of sample offset */ - uint16_t sample_offset; /* last used low order of sample-offset (effect 9) */ - uint16_t sample_offset_fine; /* fine sample offset memory */ - - /* Portamento */ - uint16_t slide_to_period; /* period to slide to (with effect 3 or 5) */ - uint8_t portamento_speed; - - /* Volume Slide */ - - uint8_t volume_slide_info; - - /* Channel Volume Slide */ - - uint8_t channel_volume_slide_info; - - /* Global Volume Slide */ - - uint8_t global_volume_slide_info; - - /* Channel Pan Slide */ - - uint8_t channel_pan_slide_info; - - /* Pitch Slide */ - - uint8_t pitch_slide_info; - /* Tempo Slide */ - - uint8_t tempo_slide_info; - - /* S effects memory */ - - uint8_t current_S_effect; - uint8_t current_S_data; - - /* Volume column memory */ - - uint8_t volume_column_effect_mem; - uint8_t volume_column_data_mem; - - int64_t last_event_usecs; - bool reserved; - - void reset(); - - Channel_Control() { channel_global_volume=255; last_event_usecs=-1; } - }; - - struct Control_Variables { // control variables (dynamic version) of initial variables - - bool reached_end; - - char play_mode; - bool filters; - int global_volume; - int speed; - int tempo; - - int ticks_counter; - - int pattern_delay_1; - int pattern_delay_2; - - Channel_Control channel[CPPattern::WIDTH]; - - int max_voices; - - int voices_used; /* reference value */ - - bool force_no_nna; - bool external_vibrato; - - struct Position { - - int current_order; - int current_pattern; - int current_row; - int force_next_order; - bool forbid_jump; - }; - - int32_t random_seed; - - Position position; - Position previous_position; - - }; - - - Voice_Control voice[MAX_VOICES]; - - Control_Variables control; - - /* VOICE SETUP */ - - void setup_voices(); - - /* MIXER SETUP */ - void handle_tick(); - void update_mixer(); - - /* NOTE / INSTRUMENT PROCESSING */ - - void process_new_note(int p_track,uint8_t p_note); - bool process_new_instrument(int p_track,uint8_t p_instrument); - bool process_note_and_instrument(int p_track,int p_note,int p_instrument); - - /* EFFECT PROCESSING */ - void do_effect_S(int p_track); - void do_panbrello(int p_track); - void do_global_volume_slide(int p_track); - void do_tremolo(int p_track); - void do_retrig(int p_track); - void do_pan_slide(int p_track); - void do_channel_volume_slide(int p_track); - void do_volume_slide(int p_track,int inf); - void do_pitch_slide_down(int p_track,uint8_t inf); - void do_pitch_slide_up(int p_track,uint8_t inf); - void do_tremor(int p_track); - void do_vibrato(int p_track,bool fine); - void do_pitch_slide_to_note(int p_track); - void run_effects(int p_track); - void run_volume_column_effects(int p_track); - void pre_process_effects(); - void do_arpegio(int p_track); - uint64_t song_usecs; - /* NNA */ - - void process_NNAs(); - - - /* MISC UTILS */ - - - int find_empty_voice(); - void process_volume_column(int p_track,uint8_t p_volume); - void process_note(int p_track,CPNote p_note); - - /* CPTables */ - static uint8_t auto_vibrato_table[128]; - static uint8_t vibrato_table[32]; - static int8_t panbrello_table[256]; - - static void callback_function(void *p_userdata); - -public: - //Play modes - - enum { - - PLAY_NOTHING =0, - PLAY_PATTERN =1, - PLAY_SONG =2 - }; - - - int32_t get_frequency(int32_t period); - int32_t get_period(uint16_t note,int32_t p_c5freq); - - - int get_current_tempo() { return control.tempo; }; - int get_current_speed() { return control.speed; }; - - int get_voices_used() { return control.voices_used;}; - int get_voice_envelope_pos(int p_voice,CPEnvelope *p_envelope); - int get_voice_amount_limit() { return control.max_voices; }; - void set_voice_amount_limit(int p_limit); - void set_reserved_voices(int p_amount); - int get_reserved_voices_amount(); - - bool is_voice_active(int p_voice); - int get_channel_voice(int p_channel); - const char* get_voice_sample_name(int p_voice); - const char* get_voice_instrument_name(int p_voice); - CPEnvelope* get_voice_envelope(int p_voice,CPInstrument::EnvelopeType p_env_type); - int get_voice_envelope_pos(int p_voice,CPInstrument::EnvelopeType p_env_type); - int get_voice_volume(int p_voice); - - int get_voice_sample_index(int p_voice); - - void set_virtual_channels(int p_amount); - int get_virtual_channels() { return control.max_voices; }; - - - /* Play Info/Position */ - bool is_playing() { return (control.play_mode>0); }; - int get_play_mode() {return (control.play_mode);}; - int get_current_order() { return control.position.current_order; }; - int get_current_row() { return control.position.current_row; }; - int get_current_pattern() { return control.position.current_pattern; }; - - void goto_next_order(); - void goto_previous_order(); - - void process_tick(); - - - CPMixer* get_mixer_ptr() { - - return mixer; - } - - - void reset(); - - - - /* External player control - editor - */ - - void play_start_pattern(int p_pattern); - void play_start_song(); - void play_start_song_from_order(int p_order); - void play_start_song_from_order_and_row(int p_order,int p_row); - void play_start(int p_pattern, int p_order, int p_row,bool p_lock=true); - - void play_stop(); - void play_note(int p_channel,CPNote note,bool p_reserve=false); - - bool reached_end_of_song(); - - void set_force_no_nna(bool p_force); - void set_force_external_vibratos(bool p_force); - - void set_filters_enabled(bool p_enable); - bool are_filters_enabled() { return control.filters; } - - void set_channel_global_volume(int p_channel,int p_volume); //0-255 - int get_channel_global_volume(int p_channel) const; - - int64_t get_channel_last_note_time_usec(int p_channel) const; - - CPSong *get_song() { return song; }; - - - CPPlayer(CPMixer *p_mixer,CPSong *p_song); - ~CPPlayer(); -}; - -#endif diff --git a/modules/chibi/cp_player_data_control.cpp b/modules/chibi/cp_player_data_control.cpp deleted file mode 100644 index 2ef1c1de8..000000000 --- a/modules/chibi/cp_player_data_control.cpp +++ /dev/null @@ -1,324 +0,0 @@ -/*************************************************************************/ -/* cp_player_data_control.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "cp_player_data.h" - -void CPPlayer::play_start_pattern(int p_pattern) { - - play_start(p_pattern,-1,-1); -} - -void CPPlayer::play_start_song() { - - play_start(-1,-1,-1); -} - -void CPPlayer::play_start_song_from_order(int p_order) { - - play_start(-1,p_order,-1); -} - -void CPPlayer::play_start_song_from_order_and_row(int p_order,int p_row) { - - play_start(-1,p_order,p_row); -} - -void CPPlayer::play_start(int p_pattern, int p_order, int p_row,bool p_lock) { - - - if (control.play_mode!=PLAY_NOTHING) play_stop(); - - - reset(); - - if (p_pattern!=-1) { - - control.play_mode=PLAY_PATTERN; - control.position.current_pattern=p_pattern; - control.position.current_row=(p_row!=-1)?p_row:0; - - } else { - - control.position.current_order=get_song_next_order_idx(song,(p_order==-1)?p_order:p_order-1); - if (control.position.current_order!=-1) { - - control.play_mode=PLAY_SONG; - control.position.current_pattern=song->get_order(control.position.current_order); - control.position.current_row=(p_row!=-1)?p_row:0; - } - } - - - control.reached_end=(control.play_mode==PLAY_NOTHING); - - -} - -void CPPlayer::play_stop() { - - int i; - - - control.play_mode=PLAY_NOTHING; - - for (i=0;i<control.max_voices;i++) { - - voice[i].reset(); - mixer->stop_voice(i); - } - - for (i=0;i<CPPattern::WIDTH;i++) { - - control.channel[i].reset(); - } - - reset(); - -} - -void CPPlayer::play_note(int p_channel,CPNote note,bool p_reserve) { - - - - if (control.play_mode==PLAY_NOTHING) { - - control.ticks_counter=0; - } - - /*control.channel[p_channel].reset(); - control.channel[p_channel].channel_volume=song->get_channel_volume(p_channel); - control.channel[p_channel].channel_panning=((int)song->get_channel_pan( p_channel)*255/64);*/ - if (p_reserve) { - control.channel[p_channel].mute=false; - control.channel[p_channel].reserved=true; - } else { - - control.channel[p_channel].reserved=false; - - } - process_note(p_channel,note); - - - -} - - -int CPPlayer::get_voice_volume(int p_voice) { - - return voice[p_voice].display_volume; -} - - -int CPPlayer::get_voice_envelope_pos(int p_voice,CPEnvelope *p_envelope) { - - int i,tmp_index=-1; - - i=p_voice; - - - - - if ((song->has_instruments()) && (voice[i].instrument_ptr!=NULL) && (voice[i].fadeout_volume>0)) { - - if ((p_envelope==voice[i].instrument_ptr->get_volume_envelope()) && (voice[i].instrument_ptr->get_volume_envelope()->is_enabled())) { - - tmp_index=voice[i].volume_envelope_ctrl.pos_index; - } - - if ((p_envelope==voice[i].instrument_ptr->get_pan_envelope()) && (voice[i].instrument_ptr->get_pan_envelope()->is_enabled())) { - - tmp_index=voice[i].panning_envelope_ctrl.pos_index; - } - - if ((p_envelope==voice[i].instrument_ptr->get_pitch_filter_envelope()) && (voice[i].instrument_ptr->get_pitch_filter_envelope()->is_enabled())) { - - - tmp_index=voice[i].pitch_envelope_ctrl.pos_index; - } - - } - - - - return tmp_index; -} - -void CPPlayer::goto_next_order() { - - - if (control.play_mode!=PLAY_SONG) return; - - - - control.position.current_row=0; - - - control.position.current_order=get_song_next_order_idx(song, control.position.current_order); - - - - if (control.position.current_order==-1) { - - reset(); - } - - control.position.current_pattern=song->get_order(control.position.current_order); - - -} -void CPPlayer::goto_previous_order() { - - if (control.play_mode!=PLAY_SONG) return; - - - int next_order,current_order; - - control.position.current_row=0; - - current_order=control.position.current_order; - - next_order=get_song_next_order_idx(song, current_order); - - while ((next_order!=control.position.current_order) && (next_order!=-1)) { - - current_order=next_order; - next_order=get_song_next_order_idx(song, current_order); - } - - if (next_order==-1) { - - reset(); - } else { - - control.position.current_order=current_order; - control.position.current_pattern=song->get_order(control.position.current_order); - - } - - - -} - -int CPPlayer::get_channel_voice(int p_channel) { - - if (control.channel[p_channel].slave_voice==NULL) return -1; - else return control.channel[p_channel].slave_voice_index; -} - -const char* CPPlayer::get_voice_sample_name(int p_voice) { - - const char *name = NULL; - - - - if (!voice[p_voice].sample_ptr) name=voice[p_voice].sample_ptr->get_name(); - - - - return name; - -} - - -bool CPPlayer::is_voice_active(int p_voice) { - - return !( ((voice[p_voice].kick==KICK_NOTHING)||(voice[p_voice].kick==KICK_ENVELOPE))&&!mixer->is_voice_active(p_voice) ); - -} - - - -int CPPlayer::get_voice_envelope_pos(int p_voice,CPInstrument::EnvelopeType p_env_type) { - - if (!is_voice_active(p_voice)) - return -1; - - Voice_Control::Envelope_Control *env=0; - - switch (p_env_type) { - - case CPInstrument::VOLUME_ENVELOPE: env=&voice[p_voice].volume_envelope_ctrl; break; - case CPInstrument::PAN_ENVELOPE: env=&voice[p_voice].panning_envelope_ctrl; break; - case CPInstrument::PITCH_ENVELOPE: env=&voice[p_voice].pitch_envelope_ctrl; break; - - } - - if (!env) - return -1; - - if (!env->active || env->terminated) - return -1; - - return env->pos_index; -} - - -CPEnvelope* CPPlayer::get_voice_envelope(int p_voice,CPInstrument::EnvelopeType p_env_type) { - - CPInstrument *ins=voice[p_voice].instrument_ptr; - - if (!ins) - return 0; - - switch( p_env_type ) { - - - case CPInstrument::VOLUME_ENVELOPE: return ins->get_volume_envelope(); - case CPInstrument::PAN_ENVELOPE: return ins->get_pan_envelope(); - case CPInstrument::PITCH_ENVELOPE: return ins->get_pitch_filter_envelope(); - }; - - return 0; - -} - -const char * CPPlayer::get_voice_instrument_name(int p_voice) { - - - - const char *name = NULL; - - - - if (voice[p_voice].instrument_ptr!=NULL) name=voice[p_voice].instrument_ptr->get_name(); - - - - return name; - -} -void CPPlayer::set_filters_enabled(bool p_enable){ - - control.filters=p_enable; -} - -int CPPlayer::get_voice_sample_index(int p_voice) { - - return voice[p_voice].sample_index; -} diff --git a/modules/chibi/cp_player_data_effects.cpp b/modules/chibi/cp_player_data_effects.cpp deleted file mode 100644 index 6c774afb1..000000000 --- a/modules/chibi/cp_player_data_effects.cpp +++ /dev/null @@ -1,1232 +0,0 @@ -/*************************************************************************/ -/* cp_player_data_effects.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "cp_player_data.h" - - - -/********************** - complex effects -***********************/ -#define RANDOM_MAX 2147483647 - -static inline int32_t cp_random_generate(int32_t *seed) { - int32_t k; - int32_t s = (int32_t)(*seed); - if (s == 0) - s = 0x12345987; - k = s / 127773; - s = 16807 * (s - k * 127773) - 2836 * k; - if (s < 0) - s += 2147483647; - (*seed) = (int32_t)s; - return (int32_t)(s & RANDOM_MAX); -} - - - -void CPPlayer::do_vibrato(int p_track,bool fine) { - - uint8_t q; - uint16_t temp=0; - - if ((control.ticks_counter==0) && control.channel[p_track].row_has_note) control.channel[p_track].vibrato_position=0; - - q=(control.channel[p_track].vibrato_position>>2)&0x1f; - - switch (control.channel[p_track].vibrato_type) { - case 0: /* sine */ - temp=vibrato_table[q]; - break; - case 1: /* square wave */ - temp=255; - break; - case 2: /* ramp down */ - q<<=3; - if (control.channel[p_track].vibrato_position<0) q=255-q; - temp=q; - break; - case 3: /* random */ - temp=cp_random_generate(&control.random_seed) %256;//getrandom(256); - break; - } - - temp*=control.channel[p_track].vibrato_depth; - - if (song->has_old_effects()) { - - temp>>=7; - } else { - - temp>>=8; - } - - if (!fine) temp<<=2; - - if (control.channel[p_track].vibrato_position>=0) { - - control.channel[p_track].period=control.channel[p_track].aux_period+temp; - } else { - - control.channel[p_track].period=control.channel[p_track].aux_period-temp; - } - - if (!song->has_old_effects() || control.ticks_counter) control.channel[p_track].vibrato_position+=control.channel[p_track].vibrato_speed; -} - - -void CPPlayer::do_pitch_slide_down(int p_track,uint8_t inf) { - - uint8_t hi,lo; - - if (inf) control.channel[p_track].pitch_slide_info=inf; - else inf=control.channel[p_track].pitch_slide_info; - - hi=inf>>4; - lo=inf&0xf; - - if (hi==0xf) { - - if (!control.ticks_counter) control.channel[p_track].aux_period+=(uint16_t)lo<<2; - } else if (hi==0xe) { - - if (!control.ticks_counter) control.channel[p_track].aux_period+=lo; - } else { - - if (control.ticks_counter) control.channel[p_track].aux_period+=(uint16_t)inf<<2; - } -} - -void CPPlayer::do_pitch_slide_up(int p_track,uint8_t inf) { - - uint8_t hi,lo; - - if (inf) control.channel[p_track].pitch_slide_info=inf; - else inf=control.channel[p_track].pitch_slide_info; - - hi=inf>>4; - lo=inf&0xf; - - if (hi==0xf) { - - if (!control.ticks_counter) control.channel[p_track].aux_period-=(uint16_t)lo<<2; - } else if (hi==0xe) { - - if (!control.ticks_counter) control.channel[p_track].aux_period-=lo; - } else { - - if (control.ticks_counter) control.channel[p_track].aux_period-=(uint16_t)inf<<2; - } -} - -void CPPlayer::do_pitch_slide_to_note(int p_track) { - - if (control.ticks_counter) { - int dist; - - /* We have to slide a->period towards a->wantedperiod, compute the - difference between those two values */ - dist=control.channel[p_track].period-control.channel[p_track].slide_to_period; - - /* if they are equal or if portamentospeed is too big... */ - if ((!dist)||((control.channel[p_track].portamento_speed<<2)>cp_intabs(dist))) { - /* ... make tmpperiod equal tperiod */ - control.channel[p_track].aux_period=control.channel[p_track].period=control.channel[p_track].slide_to_period; - } else { - - if (dist>0) { - - control.channel[p_track].aux_period-=control.channel[p_track].portamento_speed<<2; - control.channel[p_track].period-=control.channel[p_track].portamento_speed<<2; /* dist>0 slide up */ - } else { - control.channel[p_track].aux_period+=control.channel[p_track].portamento_speed<<2; - control.channel[p_track].period+=control.channel[p_track].portamento_speed<<2; /* dist<0 slide down */ - } - } - - } else { - - control.channel[p_track].aux_period=control.channel[p_track].period; - } -} - -void CPPlayer::do_tremor(int p_track) { - - uint8_t on,off,inf; - - inf=control.channel[p_track].current_parameter; - - if (inf) { - control.channel[p_track].tremor_info=inf; - } else { - inf= control.channel[p_track].tremor_info; - if (!inf) return; - } - - //if (!control.ticks_counter) return; - - on=(inf>>4); - off=(inf&0xf); - - control.channel[p_track].tremor_position%=(on+off); - control.channel[p_track].volume=(control.channel[p_track].tremor_position<on)?control.channel[p_track].aux_volume:0; - control.channel[p_track].tremor_position++; -} - -void CPPlayer::do_pan_slide(int p_track) { - - uint8_t lo,hi,inf; - int16_t pan; - - inf=control.channel[p_track].current_parameter; - - if (inf) control.channel[p_track].channel_pan_slide_info=inf; - else inf=control.channel[p_track].channel_pan_slide_info; - - lo=inf&0xf; - hi=inf>>4; - - pan=(control.channel[p_track].panning==PAN_SURROUND)?PAN_CENTER:control.channel[p_track].panning; - - if (!hi) - pan+=lo<<2; - else - if (!lo) { - pan-=hi<<2; - } else - if (hi==0xf) { - if (!control.ticks_counter) pan+=lo<<2; - } else - if (lo==0xf) { - if (!control.ticks_counter) pan-=hi<<2; - } - //this sets both chan & voice paning - control.channel[p_track].panning=(pan<PAN_LEFT)?PAN_LEFT:(pan>PAN_RIGHT?PAN_RIGHT:pan); - control.channel[p_track].channel_panning=control.channel[p_track].panning; -} - -void CPPlayer::do_volume_slide(int p_track,int inf) { - - uint8_t hi,lo; - - lo=inf&0xf; - hi=inf>>4; - - if (!lo) { - - if ((control.ticks_counter)) control.channel[p_track].aux_volume+=hi; - - } else if (!hi) { - - if ((control.ticks_counter)) control.channel[p_track].aux_volume-=lo; - - } else if (lo==0xf) { - - if (!control.ticks_counter) control.channel[p_track].aux_volume+=(hi?hi:0xf); - } else if (hi==0xf) { - - if (!control.ticks_counter) control.channel[p_track].aux_volume-=(lo?lo:0xf); - } else return; - - if (control.channel[p_track].aux_volume<0) { - - control.channel[p_track].aux_volume=0; - } else if (control.channel[p_track].aux_volume>64) { - - control.channel[p_track].aux_volume=64; - } -} - -void CPPlayer::do_channel_volume_slide(int p_track) { - - uint8_t lo, hi,inf; - - inf=control.channel[p_track].current_parameter; - - if (inf) control.channel[p_track].channel_volume_slide_info=inf; - inf=control.channel[p_track].channel_volume_slide_info; - - lo=inf&0xf; - hi=inf>>4; - - if (!hi) - control.channel[p_track].channel_volume-=lo; - else - if (!lo) { - control.channel[p_track].channel_volume+=hi; - } else - if (hi==0xf) { - if (!control.ticks_counter) control.channel[p_track].channel_volume-=lo; - } else - if (lo==0xf) { - if (!control.ticks_counter) control.channel[p_track].channel_volume+=hi; - } - - if (control.channel[p_track].channel_volume<0) control.channel[p_track].channel_volume=0; - if (control.channel[p_track].channel_volume>64) control.channel[p_track].channel_volume=64; -} - -void CPPlayer::do_tremolo(int p_track) { - - uint8_t q; - int16_t temp=0; - - if ((control.ticks_counter==0) && control.channel[p_track].row_has_note) control.channel[p_track].tremolo_position=0; - - q=(control.channel[p_track].tremolo_position>>2)&0x1f; - - switch (control.channel[p_track].tremolo_type) { - case 0: /* sine */ - temp=vibrato_table[q]; - break; - case 1: /* ramp down */ - q<<=3; - if (control.channel[p_track].tremolo_position<0) q=255-q; - temp=q; - break; - case 2: /* square wave */ - temp=255; - break; - case 3: /* random */ - temp=cp_random_generate(&control.random_seed) % 256;//getrandom(256); - break; - } - - temp*=control.channel[p_track].tremolo_depth; - temp>>=7; - - - - if (control.channel[p_track].tremolo_position>=0) { - - - control.channel[p_track].volume=control.channel[p_track].aux_volume+temp; - if (control.channel[p_track].volume>64) control.channel[p_track].volume=64; - } else { - - control.channel[p_track].volume=control.channel[p_track].aux_volume-temp; - if (control.channel[p_track].volume<0) control.channel[p_track].volume=0; - } - - /*if (control.ticks_counter)*/ control.channel[p_track].tremolo_position+=control.channel[p_track].tremolo_speed; - -} - -void CPPlayer::do_arpegio(int p_track) { - - uint8_t note,dat; - //note=control.channel[p_track].note; - note=0; - - if (control.channel[p_track].current_parameter) { - - control.channel[p_track].arpegio_info=control.channel[p_track].current_parameter; - } - - dat=control.channel[p_track].arpegio_info; - - if (dat) { - - switch (control.ticks_counter%3) { - - case 1: { - - note+=(dat>>4); - - } break; - case 2: { - - note+=(dat&0xf); - } break; - } - - if (song->has_linear_slides()) { - - control.channel[p_track].period=control.channel[p_track].aux_period-cp_intabs(get_period((uint16_t)46,0)-get_period((uint16_t)44,0))*note; - } else if (control.channel[p_track].sample_ptr) { - - control.channel[p_track].period=get_period( (((uint16_t)control.channel[p_track].note)+note)<<1,CPSampleManager::get_singleton()->get_c5_freq( (control.channel[p_track].sample_ptr->get_sample_data()))); - } - - control.channel[p_track].has_own_period=true; - } - - -} - - -void CPPlayer::do_retrig(int p_track) { - - uint8_t inf; - - inf=control.channel[p_track].current_parameter; - - if (inf) { - - control.channel[p_track].retrig_volslide=inf>>4; - control.channel[p_track].retrig_speed=inf&0xf; - } - - /* only retrigger if low nibble > 0 */ - if ( control.channel[p_track].retrig_speed>0) { - - if ( !control.channel[p_track].retrig_counter ) { - /* when retrig counter reaches 0, reset counter and restart the - sample */ - if (control.channel[p_track].kick!=KICK_NOTE) control.channel[p_track].kick=KICK_NOTEOFF; - control.channel[p_track].retrig_counter=control.channel[p_track].retrig_speed; - - - if ((control.ticks_counter)/*||(pf->flags&UF_S3MSLIDES)*/) { - switch (control.channel[p_track].retrig_volslide) { - case 1: - case 2: - case 3: - case 4: - case 5: - control.channel[p_track].aux_volume-=(1<<(control.channel[p_track].retrig_volslide-1)); - break; - case 6: - control.channel[p_track].aux_volume=(2*control.channel[p_track].aux_volume)/3; - break; - case 7: - control.channel[p_track].aux_volume>>=1; - break; - case 9: - case 0xa: - case 0xb: - case 0xc: - case 0xd: - control.channel[p_track].aux_volume+=(1<<(control.channel[p_track].retrig_volslide-9)); - break; - case 0xe: - control.channel[p_track].aux_volume=(3*control.channel[p_track].aux_volume)>>1; - break; - case 0xf: - control.channel[p_track].aux_volume=control.channel[p_track].aux_volume<<1; - break; - } - if (control.channel[p_track].aux_volume<0) control.channel[p_track].aux_volume=0; - else if (control.channel[p_track].aux_volume>64) control.channel[p_track].aux_volume=64; - } - } - control.channel[p_track].retrig_counter--; /* countdown */ - } -} - -void CPPlayer::do_global_volume_slide(int p_track) { - - uint8_t lo,hi,inf; - - inf=control.channel[p_track].current_parameter; - - if (inf) control.channel[p_track].global_volume_slide_info=inf; - inf=control.channel[p_track].global_volume_slide_info; - - lo=inf&0xf; - hi=inf>>4; - - if (!lo) { - if (control.ticks_counter) control.global_volume+=hi; - } else - if (!hi) { - if (control.ticks_counter) control.global_volume-=lo; - } else - if (lo==0xf) { - if (!control.ticks_counter) control.global_volume+=hi; - } else - if (hi==0xf) { - if (!control.ticks_counter) control.global_volume-=lo; - } - - if (control.global_volume<0) control.global_volume=0; - if (control.global_volume>128) control.global_volume=128; -} - -void CPPlayer::do_panbrello(int p_track) { - - uint8_t q; - int32_t temp=0; - - q=control.channel[p_track].panbrello_position; - - switch (control.channel[p_track].panbrello_type) { - case 0: {/* sine */ - temp=panbrello_table[q]; - } break; - case 1: {/* square wave */ - temp=(q<0x80)?64:0; - } break; - case 2: {/* ramp down */ - q<<=3; - temp=q; - } break; - case 3: {/* random */ - if (control.channel[p_track].panbrello_position>=control.channel[p_track].panbrello_speed) { - control.channel[p_track].panbrello_position=0; - temp=cp_random_generate(&control.random_seed)%256;//getrandom(256); - } - } break; - } - - - - temp=temp*(int)control.channel[p_track].panbrello_depth/0xF; - temp<<=1; - if (control.channel[p_track].channel_panning!=PAN_SURROUND) - temp+=control.channel[p_track].channel_panning; - - control.channel[p_track].panning=(temp<PAN_LEFT)?PAN_LEFT:(temp>PAN_RIGHT?PAN_RIGHT:temp); - control.channel[p_track].panbrello_position+=control.channel[p_track].panbrello_speed; -} - -/****************** - S effect -*******************/ - - -void CPPlayer::do_effect_S(int p_track) { - - uint8_t inf,c,dat; - - dat=control.channel[p_track].current_parameter; - - inf=dat&0xf; - c=dat>>4; - - if (!dat) { - c=control.channel[p_track].current_S_effect; - inf=control.channel[p_track].current_S_data; - } else { - control.channel[p_track].current_S_effect=c; - control.channel[p_track].current_S_data=inf; - } - - switch (c) { - case 1: {/* S1x set glissando voice */ - // this is unsupported in IT! - - control.channel[p_track].chorus_send=inf*0xFF/0xF; - - }break; - case 2: /* S2x set finetune */ - //Also not supported! - break; - case 3: /* S3x set vibrato waveform */ - if (inf<4) control.channel[p_track].vibrato_type=inf; - break; - case 4: /* S4x set tremolo waveform */ - if (inf<4) control.channel[p_track].tremolo_type=inf; - break; - case 5: /* S5x panbrello */ - if (inf<4) control.channel[p_track].panbrello_type=inf; - break; - case 6: {/* S6x delay x number of frames (patdly) */ - - if (control.ticks_counter) break; - if (!control.pattern_delay_2) control.pattern_delay_1=inf+1; /* only once, when vbtick=0 */ - - } break; - case 7: /* S7x instrument / NNA commands */ - - if (!song->has_instruments()) - break; - switch(inf) { - - case 0x3: { - - control.channel[p_track].NNA_type=CPInstrument::NNA_NOTE_CUT; - } break; - case 0x4: { - - control.channel[p_track].NNA_type=CPInstrument::NNA_NOTE_CONTINUE; - } break; - case 0x5: { - - control.channel[p_track].NNA_type=CPInstrument::NNA_NOTE_OFF; - } break; - case 0x6: { - - control.channel[p_track].NNA_type=CPInstrument::NNA_NOTE_FADE; - } break; - case 0x7: { - - if (control.channel[p_track].slave_voice) - control.channel[p_track].slave_voice->volume_envelope_ctrl.active=false; - } break; - case 0x8: { - - if (control.channel[p_track].slave_voice) - control.channel[p_track].slave_voice->volume_envelope_ctrl.active=true; - - } break; - case 0x9: { - - if (control.channel[p_track].slave_voice) - control.channel[p_track].slave_voice->panning_envelope_ctrl.active=false; - - } break; - case 0xA: { - - if (control.channel[p_track].slave_voice) - control.channel[p_track].slave_voice->panning_envelope_ctrl.active=true; - - } break; - case 0xB: { - if (control.channel[p_track].slave_voice) - control.channel[p_track].slave_voice->pitch_envelope_ctrl.active=false; - - } break; - case 0xC: { - - if (control.channel[p_track].slave_voice) - control.channel[p_track].slave_voice->pitch_envelope_ctrl.active=true; - - } break; - - } break; - - break; - case 8: {/* S8x set panning position */ - -// if (pf->panflag) { - if (inf<=8) inf<<=4; - else inf*=17; - control.channel[p_track].panning=control.channel[p_track].channel_panning=inf; -// } - } break; - - case 9: { /* S9x set surround sound */ - //if (pf->panflag) - control.channel[p_track].panning=control.channel[p_track].channel_panning=PAN_SURROUND; - } break; - case 0xA:{ /* SAy set high order sample offset yxx00h */ - - if (control.channel[p_track].current_parameter) control.channel[p_track].hi_offset=(int32_t)inf<<16; - control.channel[p_track].sample_start_index=control.channel[p_track].hi_offset|control.channel[p_track].lo_offset; - } break; - case 0xB: { /* SBx pattern loop */ - if (control.ticks_counter) break; - - if (inf) { /* set reppos or repcnt ? */ - /* set repcnt, so check if repcnt already is set, which means we - are already looping */ - if (control.channel[p_track].pattern_loop_count>0) - control.channel[p_track].pattern_loop_count--; /* already looping, decrease counter */ - else { - control.channel[p_track].pattern_loop_count=inf; /* not yet looping, so set repcnt */ - } - - if (control.channel[p_track].pattern_loop_count>0) { /* jump to reppos if repcnt>0 */ - - control.position=control.previous_position; // This will also anulate any Cxx or break.. - - control.position.current_row=control.channel[p_track].pattern_loop_position; - control.position.forbid_jump=true; - } - - } else { - - - control.channel[p_track].pattern_loop_position=control.position.current_row-1; - } - - } break; - case 0xC: { /* SCx notecut */ - - if (control.ticks_counter>=inf) { - - control.channel[p_track].aux_volume=0; - control.channel[p_track].note_end_flags|=END_NOTE_OFF; - control.channel[p_track].note_end_flags|=END_NOTE_KILL; - } - } break; - case 0xD: {/* SDx notedelay */ - - if (!control.ticks_counter) { - - control.channel[p_track].note_delay=inf; - - } else if (control.channel[p_track].note_delay) { - - control.channel[p_track].note_delay--; - } - - } break; - case 0xF: {/* SEx patterndelay */ - - if (control.ticks_counter) break; - if (!control.pattern_delay_2) control.pattern_delay_1=inf+1; /* only once, when vbtick=0 */ - - } break; - } -} - - - - - - - - -/********************* - volume effects -**********************/ - -void CPPlayer::run_volume_column_effects(int p_track) { - - uint8_t param=control.channel[p_track].current_volume_parameter; - - - switch ('A'+control.channel[p_track].current_volume_command) { - - case 'A': { - - if (param>0) control.channel[p_track].volcol_volume_slide=param; - else param=control.channel[p_track].volcol_volume_slide; - - do_volume_slide(p_track,param*0x10+0xF); - - } break; - case 'B': { - - if (param>0) control.channel[p_track].volcol_volume_slide=param; - else param=control.channel[p_track].volcol_volume_slide; - - do_volume_slide(p_track,0xF0+param); - - } break; - case 'C': { - - if (param>0) control.channel[p_track].volcol_volume_slide=param; - else param=control.channel[p_track].volcol_volume_slide; - - do_volume_slide(p_track,param*0x10); - } break; - case 'D': { - - if (param>0) control.channel[p_track].volcol_volume_slide=param; - else param=control.channel[p_track].volcol_volume_slide; - do_volume_slide(p_track,param); - - } break; - case 'E': { - - do_pitch_slide_down(p_track,param<<2); - } break; - case 'F': { - - do_pitch_slide_up(p_track,param<<2); - } break; - case 'G': { - - const uint8_t slide_table[]={0,1,4,8,16,32,64,96,128,255}; - if (param) { - - control.channel[p_track].portamento_speed=slide_table[param]; - } - - if (control.channel[p_track].period && (control.channel[p_track].old_note<=120)) { - - if ( (!control.ticks_counter) && (control.channel[p_track].new_instrument) ){ - - //control.channel[p_track].kick=KICK_NOTE; - //control.channel[p_track].sample_start_index=0; // < am i stupid? - } else { - - control.channel[p_track].kick=(control.channel[p_track].kick==KICK_NOTE)?KICK_ENVELOPE:KICK_NOTHING; - do_pitch_slide_to_note(p_track); - control.channel[p_track].has_own_period=true; - } - - } - } break; - case 'H': { - - - if (!control.ticks_counter) { - if (param&0x0f) control.channel[p_track].vibrato_depth=param; - } - control.channel[p_track].doing_vibrato=true; - if (control.external_vibrato) break; - if (control.channel[p_track].period) { - - do_vibrato(p_track,false); - control.channel[p_track].has_own_period=true; - } - - } break; - } -} -/********************* - table -**********************/ - - -void CPPlayer::run_effects(int p_track) { - - switch ('A'+control.channel[p_track].current_command) { - - case 'A': { - - if ((control.ticks_counter>0) || (control.pattern_delay_2>0)) break; - - int new_speed; - - new_speed=control.channel[p_track].current_parameter % 128; - - if (new_speed>0) { - control.speed=new_speed; - control.ticks_counter=0; - } - } break; - case 'B': { - - int next_order; - - if (control.ticks_counter || control.position.forbid_jump) break; - - control.position.current_row=0; - - if (control.play_mode==PLAY_PATTERN) break; - - next_order=get_song_next_order_idx(song, (int)control.channel[p_track].current_parameter-1); - - if (next_order!=-1) { - // Do we have a "next order?" - control.position.current_pattern=song->get_order(next_order); - control.position.force_next_order=next_order; - - } else { - // no, probably the user deleted the orderlist. - control.play_mode=PLAY_NOTHING; - reset(); - } - } break; - case 'C': { - - int next_order; - - if (control.ticks_counter || control.position.forbid_jump) break; - - control.position.current_row=control.channel[p_track].current_parameter; - - if (control.play_mode==PLAY_PATTERN) { - - if (control.position.current_row>=song->get_pattern(control.position.current_pattern)->get_length()) { - - control.position.current_row=0; - } - - break; - } - - next_order=get_song_next_order_idx(song, (int)control.position.current_order); - - if (next_order!=-1) { - // Do we have a "next order?" - control.position.current_pattern=song->get_order(next_order); - - if (control.position.current_row>=song->get_pattern(song->get_order(next_order))->get_length()) { - - control.position.current_row=0; - } - - control.position.force_next_order=next_order; - - } else { - // no, probably the user deleted the orderlist. - control.play_mode=PLAY_NOTHING; - reset(); - } - - } break; - case 'D': { - - uint8_t inf ; - //explicitslides=1; - inf=control.channel[p_track].current_parameter; - - if (inf) control.channel[p_track].volume_slide_info=inf; - else inf=control.channel[p_track].volume_slide_info; - - do_volume_slide(p_track,inf); - - } break; - case 'E': { - - uint8_t inf; - - inf=control.channel[p_track].current_parameter; - do_pitch_slide_down(p_track,inf); - - } break; - case 'F': { - - uint8_t inf; - - inf=control.channel[p_track].current_parameter; - do_pitch_slide_up(p_track,inf); - - } break; - case 'G': { - - if (control.channel[p_track].current_parameter) { - - control.channel[p_track].portamento_speed=control.channel[p_track].current_parameter; - } - - if (control.channel[p_track].period && (control.channel[p_track].old_note<=120)) { - - if ( (!control.ticks_counter) && (control.channel[p_track].new_instrument) ){ - - - control.channel[p_track].kick=KICK_NOTE; - control.channel[p_track].sample_start_index=0; - - } else { - - control.channel[p_track].kick=(control.channel[p_track].kick==KICK_NOTE)?KICK_ENVELOPE:KICK_NOTHING; - } - - do_pitch_slide_to_note(p_track); - control.channel[p_track].has_own_period=true; - } - - } break; - case 'H': { - - uint8_t dat; - - control.channel[p_track].doing_vibrato=true; - - dat=control.channel[p_track].current_parameter; - - if (!control.ticks_counter) { - if (dat&0x0f) control.channel[p_track].vibrato_depth=dat&0xf; - if (dat&0xf0) control.channel[p_track].vibrato_speed=(dat&0xf0)>>2; - } - - if (control.external_vibrato) break; - - if (control.channel[p_track].period) { - - do_vibrato(p_track,false); - control.channel[p_track].has_own_period=true; - } - - } break; - case 'I': { - - do_tremor(p_track); - control.channel[p_track].has_own_volume=true; - } break; - case 'J': { - - do_arpegio(p_track); - } break; - case 'K': { - - uint8_t inf ; - //explicitslides=1; - inf=control.channel[p_track].current_parameter; - - control.channel[p_track].doing_vibrato=true; - - - if (inf) control.channel[p_track].volume_slide_info=inf; - else inf=control.channel[p_track].volume_slide_info; - - do_volume_slide(p_track,inf); - - if (control.external_vibrato) break; - - if (control.channel[p_track].period) { - - do_vibrato(p_track,false); - control.channel[p_track].has_own_period=true; - } - - } break; - case 'L': { - uint8_t inf ; - //explicitslides=1; - inf=control.channel[p_track].current_parameter; - - if (inf) control.channel[p_track].volume_slide_info=inf; - else inf=control.channel[p_track].volume_slide_info; - - do_volume_slide(p_track,inf); - - if (control.channel[p_track].period && (control.channel[p_track].old_note<=120)) { - if ( (!control.ticks_counter) && (control.channel[p_track].new_instrument) ){ - - control.channel[p_track].kick=KICK_NOTE; - control.channel[p_track].sample_start_index=0; - - } else { - - control.channel[p_track].kick=(control.channel[p_track].kick==KICK_NOTE)?KICK_ENVELOPE:KICK_NOTHING; - } - - do_pitch_slide_to_note(p_track); - control.channel[p_track].has_own_period=true; - } - } break; - case 'M': { - control.channel[p_track].channel_volume=control.channel[p_track].current_parameter; - if (control.channel[p_track].channel_volume>64) control.channel[p_track].channel_volume=64; - else if (control.channel[p_track].channel_volume<0) control.channel[p_track].channel_volume=0; - } break; - case 'N': { - - do_channel_volume_slide(p_track); - } - case 'O': { - - if (!control.ticks_counter) { - - if (control.channel[p_track].current_parameter) control.channel[p_track].lo_offset=(uint16_t)control.channel[p_track].current_parameter<<8; - control.channel[p_track].sample_start_index=control.channel[p_track].hi_offset|control.channel[p_track].lo_offset; - - //if ((control.channel[p_track].sample_ptr!=NULL)&&(control.channel[p_track].sample_start_index>control.channel[p_track].sample_ptr->data.size)) { - //TODO, O effect - //a->start=a->s->flags&(SF_LOOP|SF_BIDI)?a->s->loopstart:a->s->length; - //} - } - } break; - case 'P': { - - do_pan_slide(p_track); - } break; - case 'Q': { - do_retrig(p_track); - - } break; - case 'R': { - - - uint8_t dat; - - if (control.channel[p_track].current_parameter) { - - control.channel[p_track].tremolo_info=control.channel[p_track].current_parameter; - } - - dat=control.channel[p_track].tremolo_info; - - if (!control.ticks_counter && dat) { - - if (dat&0x0f) control.channel[p_track].tremolo_depth=dat&0xf; - if (dat&0xf0) control.channel[p_track].tremolo_speed=(dat&0xf0)>>2; - } - - do_tremolo(p_track); - control.channel[p_track].has_own_volume=true; - - } break; - case 'S': { - - do_effect_S(p_track); - } break; - case 'T': { - uint8_t dat; - int16_t temp=control.tempo; - - if (control.pattern_delay_2) return; - - if (control.channel[p_track].current_parameter) { - - control.channel[p_track].tempo_slide_info=control.channel[p_track].current_parameter; - } - - dat=control.channel[p_track].tempo_slide_info; - - if (dat>=0x20) { - - if (control.ticks_counter) break; - control.tempo=dat; - } else { - - if (!control.ticks_counter) break; - - if (dat&0x10) { - - temp+=(dat&0x0f); - } else { - - temp-=dat; - } - control.tempo=(temp>255)?255:(temp<0x20?0x20:temp); - } - - } break; - case 'U': { - - uint8_t dat; - - dat=control.channel[p_track].current_parameter; - control.channel[p_track].doing_vibrato=true; - if (!control.ticks_counter) { - if (dat&0x0f) control.channel[p_track].vibrato_depth=dat&0xf; - if (dat&0xf0) control.channel[p_track].vibrato_speed=(dat&0xf0)>>2; - } - - if (control.external_vibrato) break; - - if (control.channel[p_track].period) { - - do_vibrato(p_track,true); - control.channel[p_track].has_own_period=true; - } - } break; - case 'V': { - - control.global_volume=control.channel[p_track].current_parameter; - if (control.global_volume>128) control.global_volume=128; - } break; - case 'W': { - do_global_volume_slide(p_track); - } break; - case 'X': { - //sets both channel and current - control.channel[p_track].channel_panning=control.channel[p_track].current_parameter; - control.channel[p_track].panning=control.channel[p_track].current_parameter; - } break; - case 'Y': { - - uint8_t dat; - - if (control.channel[p_track].current_parameter) { - - control.channel[p_track].panbrello_info=control.channel[p_track].current_parameter; - } - - dat=control.channel[p_track].panbrello_info; - - if (!control.ticks_counter) { - - if (dat&0x0f) control.channel[p_track].panbrello_depth=(dat&0xf); - if (dat&0xf0) control.channel[p_track].panbrello_speed=(dat&0xf0)>>4; - } - - //if (pf->panflag) - if (control.channel[p_track].panning!=PAN_SURROUND)do_panbrello(p_track); - - } break; - case 'Z': { - //I DO! cuttoff! - uint16_t dat=control.channel[p_track].current_parameter; - - if (dat<0x80) { - - control.channel[p_track].filter.it_cutoff=dat*2; - if (control.channel[p_track].filter.it_cutoff>0x80) - control.channel[p_track].filter.it_cutoff++; - } else if (dat<0x90) { - - control.channel[p_track].filter.it_reso=(dat-0x80)*0x10; - } else { - - control.channel[p_track].reverb_send=(dat-0x90)*255/0x6F; - } - - } break; - - } - -} - -void CPPlayer::pre_process_effects() { - -// MP_VOICE *aout; - int i; - - for (i=0;i<CPPattern::WIDTH;i++) { - - //a=&pf->control[mp_channel]; - - // if ((aout=a->slave)) { - // a->fadevol=aout->fadevol; - // a->period=aout->period; - // if (a->kick==KICK_KEYOFF) a->keyoff=aout->keyoff; - //} - - //if (!a->row) continue; - //UniSetRow(a->row); - control.channel[i].has_own_period=false; - control.channel[i].has_own_volume=false; - control.channel[i].doing_vibrato=false; - //explicitslides=0; - //pt_playeffects(); - if (control.ticks_counter<control.speed) { - - run_effects(i); - run_volume_column_effects(i); - } - - /* continue volume slide if necessary for XM and IT */ - //if (pf->flags&UF_BGSLIDES) { - // if (!explicitslides && a->sliding) - // DoS3MVolSlide(0); - // else if (a->tmpvolume) a->sliding=explicitslides; - //} - - if (!control.channel[i].has_own_period) control.channel[i].period=control.channel[i].aux_period; - if (!control.channel[i].has_own_volume) control.channel[i].volume=control.channel[i].aux_volume; - - if ((control.channel[i].sample_ptr!=NULL) && !(song->has_instruments() && (control.channel[i].instrument_ptr==NULL))) { - - if (song->has_instruments()) { - - control.channel[i].output_volume= - (control.channel[i].volume*control.channel[i].sample_ptr->get_global_volume()*control.channel[i].instrument_ptr->get_volume_global_amount())/2048; - control.channel[i].output_volume=control.channel[i].output_volume*control.channel[i].random_volume_variation/100; - - } else { - - control.channel[i].output_volume= - (control.channel[i].volume*control.channel[i].sample_ptr->get_global_volume())>>4; - - } - - if (control.channel[i].output_volume>256) { - - control.channel[i].output_volume=256; - - } else if (control.channel[i].output_volume<0) { - - control.channel[i].output_volume=0; - } - - - } - } - -} diff --git a/modules/chibi/cp_player_data_envelopes.cpp b/modules/chibi/cp_player_data_envelopes.cpp deleted file mode 100644 index a720eaf73..000000000 --- a/modules/chibi/cp_player_data_envelopes.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/*************************************************************************/ -/* cp_player_data_envelopes.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "cp_player_data.h" - - -void CPPlayer::Voice_Control::start_envelope(CPEnvelope *p_envelope,Envelope_Control *p_envelope_ctrl,Envelope_Control *p_from_env) { - - - if (p_from_env && p_envelope->is_carry_enabled() && !p_from_env->terminated) { - - - *p_envelope_ctrl=*p_from_env; - } else { - p_envelope_ctrl->pos_index=0; - p_envelope_ctrl->status=1; - p_envelope_ctrl->sustain_looping=p_envelope->is_sustain_loop_enabled(); - p_envelope_ctrl->looping=p_envelope->is_loop_enabled(); - p_envelope_ctrl->terminated=false; - p_envelope_ctrl->kill=false; - p_envelope_ctrl->value=p_envelope->get_height_at_pos(p_envelope_ctrl->pos_index); - } -} - -bool CPPlayer::Voice_Control::process_envelope(CPEnvelope *p_envelope,Envelope_Control *p_envelope_ctrl) { - - if (!p_envelope_ctrl->active) - return false; - - if (note_end_flags&END_NOTE_OFF) p_envelope_ctrl->sustain_looping=false; - - p_envelope_ctrl->value=p_envelope->get_height_at_pos(p_envelope_ctrl->pos_index); - if (p_envelope_ctrl->value==CPEnvelope::NO_POINT) - return false; - - - p_envelope_ctrl->pos_index++; - - if (p_envelope_ctrl->sustain_looping) { - - if (p_envelope_ctrl->pos_index>p_envelope->get_node(p_envelope->get_sustain_loop_end()).tick_offset) { - - p_envelope_ctrl->pos_index=p_envelope->get_node(p_envelope->get_sustain_loop_begin()).tick_offset; - } - - } else if (p_envelope_ctrl->looping) { - - if (p_envelope_ctrl->pos_index>p_envelope->get_node(p_envelope->get_loop_end()).tick_offset) { - - p_envelope_ctrl->pos_index=p_envelope->get_node(p_envelope->get_loop_begin()).tick_offset; - } - - } - - if (p_envelope_ctrl->pos_index>p_envelope->get_node(p_envelope->get_node_count()-1).tick_offset) { - - p_envelope_ctrl->terminated=true; - p_envelope_ctrl->pos_index=p_envelope->get_node(p_envelope->get_node_count()-1).tick_offset; - if (p_envelope->get_node(p_envelope->get_node_count()-1).value==0) p_envelope_ctrl->kill=true; - } - - return true; -} diff --git a/modules/chibi/cp_player_data_events.cpp b/modules/chibi/cp_player_data_events.cpp deleted file mode 100644 index 7ec3f1931..000000000 --- a/modules/chibi/cp_player_data_events.cpp +++ /dev/null @@ -1,679 +0,0 @@ -/*************************************************************************/ -/* cp_player_data_events.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "cp_player_data.h" -#include "cp_sample_manager.h" -#include "stdio.h" -/* - setup_voices(): - -This will go throught all the REAL channels, if it finds a channel -that needs to be restarted or assigned a new VIRTUAL channel, then it -will just find one and do it. - -*/ - - -#define C5FREQ 261.6255653006 -static const int32_t C5FREQ_MIXER = ((int32_t)(C5FREQ*(float)(1<<CPMixer::FREQUENCY_BITS))); - - -void CPPlayer::setup_voices() { - - int i,voice_index; - - - - - for (i=0;i<CPPattern::WIDTH;i++) { - - voice_index=-1; - - if (control.channel[i].note_delay) continue; - - - // check if we need a new empty voice - if (control.channel[i].kick==KICK_NOTE) { - - /* if no channel was cut above, find an empty or quiet channel - here */ - if ( song->has_instruments() && !control.force_no_nna) { - - if (control.channel[i].slave_voice==NULL) { // no slave?? - - int newchn; - if ((newchn=find_empty_voice())!=-1) { - - control.channel[i].slave_voice_index=newchn; - control.channel[i].slave_voice=&voice[newchn]; - } - } - - } else { - if (i<control.max_voices) { - - control.channel[i].slave_voice_index=i; - control.channel[i].slave_voice=&voice[i]; - } else { - //This is a _DIRTY_ hack, but i cant think a better way. - control.channel[i].slave_voice_index=control.max_voices-1; - control.channel[i].slave_voice=&voice[control.max_voices-1]; - } - - } - - - /* assign parts of MP_VOICE only done for a KICK_NOTE */ - if ( ( control.channel[i].slave_voice!=NULL ) ) { - - voice_index=control.channel[i].slave_voice_index; - Voice_Control &v=voice[voice_index]; - - if (v.has_master_channel && (v.master_channel!=NULL) ) { - // If this voice already has a master channel, make sure to remove the reference to it. - v.master_channel->slave_voice=NULL; - - } - //notify the voice that the current channel is the master - v.master_channel=&control.channel[i]; - //set the voice as slave of the current channel - control.channel[i].slave_voice=&v; - //master channel index of the voice - v.master_channel_index=i; - v.has_master_channel=true; - } - - } else { - // nope.. - // so if we DO have a slave voice then use it. - if ( control.channel[i].slave_voice!=NULL ) { - - voice_index=control.channel[i].slave_voice_index; - } - } - //assuming this channel has a slave voice.. - if (voice_index>=0) { - - // IMPROVE: Code a method for this: - voice[voice_index].update_info_from_master_channel(); - } - - control.channel[i].kick=KICK_NOTHING; - } -} -void CPPlayer::Voice_Control::reset() { - - cp_memzero(this,sizeof(*this)); - - instrument_ptr=NULL; - sample_ptr=NULL; - has_master_channel=false; - instrument_index=-1; - reverb_send=0; - chorus_send=0; - filter.it_cutoff=255; - filter.it_reso=0; - display_volume=0; - - -} - -void CPPlayer::Channel_Control::reset() { - - int prev_gv =channel_global_volume; - cp_memzero(this,sizeof(*this)); - - slave_voice=NULL; - slave_voice_index=255; - - mute=false; - old_note=255; - real_note=255; - instrument_index=255; - filter.it_cutoff=255; - filter.it_reso=0; - reverb_send=0; - chorus_send=0; - reserved=false; - carry.maybe=false; - last_event_usecs=-1; - channel_global_volume=prev_gv; -} - -void CPPlayer::Voice_Control::update_info_from_master_channel() { - - instrument_ptr=master_channel->instrument_ptr; - sample_ptr=master_channel->sample_ptr; - - instrument_index=master_channel->instrument_index; - sample_index=master_channel->sample_index; - - note=master_channel->note; - output_volume=master_channel->output_volume; - - channel_volume=master_channel->channel_volume; - - panning=master_channel->panning; - - kick=master_channel->kick; - note_end_flags=master_channel->note_end_flags; - period=master_channel->period; - - volume_envelope_ctrl.active=master_channel->volume_envelope_on; - panning_envelope_ctrl.active=master_channel->panning_envelope_on; - pitch_envelope_ctrl.active=master_channel->pitch_envelope_on; - - - NNA_type=master_channel->NNA_type; - reverb_send=master_channel->reverb_send; - chorus_send=master_channel->chorus_send; - -// last_note_type=master_channel->last_note_type; - - sample_start_index=master_channel->sample_start_index; - filter=master_channel->filter; - -} - - -void CPPlayer::update_mixer() { - - int tmp_mixer_period; - int32_t tmp_vibrato_value,tmp_vibrato_depth,tmp_volenv_value; - uint64_t tmpvol; // 64bits should be the only way to avoid getting notes raped out - int i; - - - control.voices_used=0; - - for (i=0;i<control.max_voices;i++) { - - - int filter_env=-1; - Voice_Control &v=voice[i]; - - if ( !((v.kick==KICK_NOTE)||(v.kick==KICK_NOTEOFF)) && !is_voice_active(i)) - continue; - - //if voice doesnt have a sample set or size is 0.. forget it - if ( v.sample_ptr==NULL) continue; - - - //TODO set limits somewhere else - - if (v.period<40) { - - v.period=40; - - } else if (v.period>50000) { - - v.period=50000; - } - - - if ((v.kick==KICK_NOTE)||(v.kick==KICK_NOTEOFF)) { - - int real_start_index; - - if (v.sample_start_index==-1) { - - real_start_index=0; - - } else { - - real_start_index=v.sample_start_index; - } - - mixer->setup_voice(i,v.sample_ptr->get_sample_data(),real_start_index); - v.fadeout_volume=1024; //IT Docs it is 1024 internally - v.auto_vibrato_sweep_pos=0; - - - - } - - - /* Start Envelopes */ - if ( song->has_instruments() && ((v.kick==KICK_NOTE)||(v.kick==KICK_ENVELOPE))) { - -// Voice_Control *carry=0; - - - if (v.has_master_channel && v.master_channel->carry.maybe) { - - v.start_envelope(v.instrument_ptr->get_volume_envelope(),&v.volume_envelope_ctrl,&v.master_channel->carry.vol); - v.start_envelope(v.instrument_ptr->get_pan_envelope(),&v.panning_envelope_ctrl,&v.master_channel->carry.pan); - v.start_envelope(v.instrument_ptr->get_pitch_filter_envelope(),&v.pitch_envelope_ctrl,&v.master_channel->carry.pitch); - - } else { - - v.start_envelope(v.instrument_ptr->get_volume_envelope(),&v.volume_envelope_ctrl,NULL); - v.start_envelope(v.instrument_ptr->get_pan_envelope(),&v.panning_envelope_ctrl,NULL); - v.start_envelope(v.instrument_ptr->get_pitch_filter_envelope(),&v.pitch_envelope_ctrl,NULL); - - } - - - } - - v.kick=KICK_NOTHING; - - if (song->has_instruments()) { - - if (!v.process_envelope(v.instrument_ptr->get_volume_envelope(),&v.volume_envelope_ctrl)) - v.volume_envelope_ctrl.value=64; - - if (!v.process_envelope(v.instrument_ptr->get_pan_envelope(),&v.panning_envelope_ctrl)) - v.panning_envelope_ctrl.value=0; - - if (!v.process_envelope(v.instrument_ptr->get_pitch_filter_envelope(),&v.pitch_envelope_ctrl)) - v.pitch_envelope_ctrl.value=0; - - - if (v.volume_envelope_ctrl.terminated) { - - if (v.volume_envelope_ctrl.kill) { - - v.fadeout_volume=0; - } else { - - v.note_end_flags|=END_NOTE_FADE; - } - } - - } - - if (song->has_instruments()) { - - tmp_volenv_value=v.volume_envelope_ctrl.value; - } else { - - tmp_volenv_value=64; - - } - - /*printf("fadeout %i\n",(int)v.fadeout_volume); - printf("channel %i\n",(int)v.channel_volume); - printf("output %i\n",(int)v.output_volume); - printf("env %i\n",(int)tmp_volenv_value); - printf("cgb %i\n",(int)v.master_channel->channel_global_volume); -*/ - - - tmpvol=(uint64_t)v.fadeout_volume; /* max 1024 - 10 bits */ - tmpvol*=(uint64_t)v.channel_volume; /* * max 64 - 6 bits */ - tmpvol*=(uint64_t)v.output_volume; /* * max 256 - 8 bits */ - tmpvol*=(uint64_t)tmp_volenv_value; /* max 64 - 6 bits*/ - tmpvol*=(uint64_t)v.master_channel->channel_global_volume; - v.display_volume=tmpvol>>22; //volume used for display purposes , 0 -- 256 - - tmpvol*=(uint64_t)song->get_mixing_volume(); /* max 128 - 7 bits */ - tmpvol*=(uint64_t)control.global_volume; /* max 128 - 7 bits*/ - /* total 10+6+8+6+7+7=44 bits */ - - tmpvol>>=43; /* Move back to 8 bits range , 44-19+8=43*/ - - if (tmpvol>CP_VOL_MAX) - tmpvol=CP_VOL_MAX; - - //printf("volume check - fade %i, channel %i, output %i, env %i, mix %i, global %i -- final %i\n",v.fadeout_volume, v.channel_volume,v.output_volume,tmp_volenv_value, song->get_mixing_volume(),control.global_volume,tmpvol); - - v.total_volume=tmpvol; - - - if ((v.master_channel!=NULL) && song->is_channel_mute( v.master_channel_index ) && !v.master_channel->reserved) { - - mixer->set_voice_volume(i,0); - } else { - mixer->set_voice_volume(i,tmpvol); - if (v.fadeout_volume>0) control.voices_used++; - } - - - if (!song->is_stereo()) { - - mixer->set_voice_panning(i,PAN_CENTER); - - } else if (v.panning==PAN_SURROUND) { - - mixer->set_voice_panning(i,PAN_SURROUND); - } else if (song->has_instruments()) { - - int newpan,real_modifier; - - - real_modifier=(v.panning_envelope_ctrl.value*(PAN_CENTER-cp_intabs(v.panning-PAN_CENTER)))/32; - - newpan=v.panning+real_modifier; - - newpan=(newpan<PAN_LEFT)?PAN_LEFT:(newpan>PAN_RIGHT)?PAN_RIGHT:newpan; - //printf("panenv val: %i, finalpan val %i\n",v.panning_envelope_ctrl.value,newpan); - - mixer->set_voice_panning(i,newpan); - } else { - mixer->set_voice_panning(i,v.panning); - } - - - - /* VIBRATO */ - - if ( (v.period>0) && (v.sample_ptr->get_vibrato_depth()>0) ) { - - switch (v.sample_ptr->get_vibrato_type()) { - case CPSample::VIBRATO_SINE: - tmp_vibrato_value=auto_vibrato_table[v.auto_vibrato_pos&127]; - if (v.auto_vibrato_pos & 0x80) tmp_vibrato_value=-tmp_vibrato_value; - break; - case CPSample::VIBRATO_SQUARE: - tmp_vibrato_value=64; - if (v.auto_vibrato_pos & 0x80) tmp_vibrato_value=-tmp_vibrato_value; - break; - case CPSample::VIBRATO_SAW: - tmp_vibrato_value=63-(((v.auto_vibrato_pos+128)&255)>>1); - break; - default: - tmp_vibrato_value=(((v.auto_vibrato_pos+128)&255)>>1)-64; - break; - } - } else { - - tmp_vibrato_value=0; - } - - if ((v.auto_vibrato_sweep_pos>>8)<v.sample_ptr->get_vibrato_depth()) { - - v.auto_vibrato_sweep_pos+=v.sample_ptr->get_vibrato_speed(); //FIXME - speed? i think so - tmp_vibrato_depth=v.auto_vibrato_sweep_pos; - - } else { - - tmp_vibrato_depth=v.sample_ptr->get_vibrato_depth()<<8; - } - - tmp_vibrato_value=(tmp_vibrato_value*tmp_vibrato_depth)>>16; - if (song->has_linear_slides()) - tmp_vibrato_value>>=1; - v.period-=tmp_vibrato_value; - - - /* update vibrato position */ - v.auto_vibrato_pos=(v.auto_vibrato_pos+v.sample_ptr->get_vibrato_rate())&0xff; - - - /* process pitch envelope */ - tmp_mixer_period=v.period; - - if (v.pitch_envelope_ctrl.active) { - - long aux_pitch_diff; - int pe_value=v.pitch_envelope_ctrl.value; - - if (!v.instrument_ptr->is_pitch_use_as_filter()) { - - - if (((uint16_t)v.note<<1)+pe_value<=0) - pe_value=-(v.note<<1); - - int smp_c5=CPSampleManager::get_singleton()->get_c5_freq( v.sample_ptr->get_sample_data()); - - int base=get_period(((uint16_t)v.note<<1),smp_c5); - int env=get_period(((uint16_t)v.note<<1)+pe_value,smp_c5); - /* - int env_next=(pe_value<0)?get_period(((uint16_t)(v.note-1)<<1)+pe_value,smp_c5):get_period(((uint16_t)(v.note+1)<<1)+pe_value,smp_c5); - - env=env+(abs(v.pitch_envelope_ctrl.value)&((1<<CPEnvelope::FX_HEIGHT_BITS)-1))*(env_next-env)/(1<<CPEnvelope::FX_HEIGHT_BITS); - - printf("env %i\n",env); - */ - aux_pitch_diff=env-base; - - - if ( ((int)tmp_mixer_period-aux_pitch_diff)<0 ) aux_pitch_diff=0; - - tmp_mixer_period+=aux_pitch_diff; - - } else { - - filter_env=pe_value+32; //max 64 -// printf("pitch envelope at %i",filter_env); - - } - } - - if (v.fadeout_volume==0 || (v.note_end_flags & END_NOTE_KILL)) { /* check for a dead note (fadevol=0) */ - - mixer->stop_voice(i); - - } else { - - - int32_t freq=get_frequency(tmp_mixer_period); - int32_t tracker_c5=get_frequency(get_period(60<<1,CPSampleManager::get_singleton()->get_c5_freq( v.sample_ptr->get_sample_data()))); - - freq=(int32_t)((uint64_t)freq*(uint64_t)C5FREQ_MIXER/(uint64_t)tracker_c5); //numbers may become very high - mixer->set_voice_frequency(i,freq); - - /* if keyfade, start substracting fadeoutspeed from fadevol: */ - if ((song->has_instruments())&&(v.note_end_flags & END_NOTE_FADE)) { - - if (v.fadeout_volume>=(v.instrument_ptr->get_volume_fadeout())) { - - v.fadeout_volume-=(v.instrument_ptr->get_volume_fadeout()); - } else { - - v.fadeout_volume=0; - } - } - - /*FILTARSSSSSSSS*/ - - - - v.filter.envelope_cutoff=filter_env; - v.filter.process(); - - if ((v.filter.final_cutoff<0xFF) && (control.filters)) { - - //int final_cutoff; - //uint8_t final_reso; - - //v.filter.set_filter_parameters( &final_cutoff, &final_reso ); - - mixer->set_voice_filter(i,true,v.filter.final_cutoff,v.filter.it_reso); - } else { - - - mixer->set_voice_filter(i,false,0,0); - } - - /* RAIVERV */ - - mixer->set_voice_reverb_send(i,v.reverb_send); - - /* CHAURUZ */ - - mixer->set_voice_chorus_send(i,v.chorus_send); - - } - } - - - switch(song->get_reverb_mode()) { - - case CPSong::REVERB_MODE_ROOM: { - - mixer->set_reverb_mode( CPMixer::REVERB_MODE_ROOM ); - } break; - case CPSong::REVERB_MODE_STUDIO_SMALL: { - - mixer->set_reverb_mode( CPMixer::REVERB_MODE_STUDIO_SMALL ); - - } break; - case CPSong::REVERB_MODE_STUDIO_MEDIUM: { - - mixer->set_reverb_mode( CPMixer::REVERB_MODE_STUDIO_MEDIUM ); - - } break; - case CPSong::REVERB_MODE_STUDIO_LARGE: { - - mixer->set_reverb_mode( CPMixer::REVERB_MODE_STUDIO_LARGE ); - - } break; - case CPSong::REVERB_MODE_HALL: { - - mixer->set_reverb_mode( CPMixer::REVERB_MODE_HALL ); - - } break; - case CPSong::REVERB_MODE_SPACE_ECHO: { - - mixer->set_reverb_mode( CPMixer::REVERB_MODE_SPACE_ECHO ); - - } break; - case CPSong::REVERB_MODE_ECHO: { - - mixer->set_reverb_mode( CPMixer::REVERB_MODE_ECHO ); - - } break; - case CPSong::REVERB_MODE_DELAY: { - - mixer->set_reverb_mode( CPMixer::REVERB_MODE_DELAY ); - - } break; - case CPSong::REVERB_MODE_HALF_ECHO: { - - mixer->set_reverb_mode( CPMixer::REVERB_MODE_HALF_ECHO ); - - } break; - - } - - mixer->set_chorus_params(song->get_chorus_delay_ms(),song->get_chorus_separation_ms(),song->get_chorus_depth_ms10(),song->get_chorus_speed_hz10() ); - - -} - - - - - - - - -void CPPlayer::handle_tick() { - - int i; - - - if ( mixer==NULL ) return; - if ( song==NULL ) return; - - - /* update time counter (sngtime is in milliseconds (in fact 2^-10)) */ - - if (control.ticks_counter>=control.speed) { // time to process... ***THE ROW***! - - /* process pattern-delay. pf->patdly2 is the counter and pf->patdly is - the command memory. */ - -// if (control.pattern_delay_1) { - -// control.pattern_delay_2=control.pattern_delay_1; -// control.pattern_delay_1=0; -// } -// if (control.pattern_delay_2) { -// patterndelay active -// if (--control.pattern_delay_2) -// so turn back pf->patpos by 1 -// if (pf->patpos) pf->patpos--; -// } - - if (control.play_mode!=PLAY_NOTHING) { - - control.ticks_counter=0; - - - if (control.position.force_next_order>=0) { - - control.position.current_order=control.position.force_next_order; - } - - control.position.force_next_order=-1; - - control.previous_position=control.position; // for those special cases... - control.position.forbid_jump=false; - - for (i=0;i<CPPattern::WIDTH;i++) { - - process_note(i,song->get_pattern(control.position.current_pattern)->get_note(i,control.position.current_row)); - } - - control.position.current_row++; - - if ( control.position.current_row>=song->get_pattern(control.position.current_pattern)->get_length() ) { - - if (control.play_mode==PLAY_SONG) { - - int next_order; - - next_order=get_song_next_order_idx(song,control.position.current_order); - - if (next_order!=-1) { - // Do we have a "next order?" - control.position.current_pattern=song->get_order(next_order); - if (next_order<=control.position.current_order) - control.reached_end=true; - control.position.current_order=next_order; - - } else { - // no, probably the user deleted the orderlist. - control.play_mode=PLAY_NOTHING; - reset(); - control.reached_end=true; - } - } - control.position.current_row=0; - } - - } - - - } - - - - pre_process_effects(); - process_NNAs(); - setup_voices(); - - /* now set up the actual hardware channel playback information */ - update_mixer(); - - control.ticks_counter++; -} diff --git a/modules/chibi/cp_player_data_filter.cpp b/modules/chibi/cp_player_data_filter.cpp deleted file mode 100644 index e04ae126f..000000000 --- a/modules/chibi/cp_player_data_filter.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/*************************************************************************/ -/* cp_player_data_filter.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - - -#include "cp_player_data.h" - -static float filter_cutoff[256] = { - 130, 132, 134, 136, 138, 140, 142, 144, - 146, 148, 151, 153, 155, 157, 160, 162, - 164, 167, 169, 172, 174, 177, 179, 182, - 184, 187, 190, 193, 195, 198, 201, 204, - 207, 210, 213, 216, 220, 223, 226, 229, - 233, 236, 239, 243, 246, 250, 254, 257, - 261, 265, 269, 273, 277, 281, 285, 289, - 293, 297, 302, 306, 311, 315, 320, 324, - 329, 334, 339, 344, 349, 354, 359, 364, - 369, 375, 380, 386, 391, 397, 403, 409, - 415, 421, 427, 433, 440, 446, 452, 459, - 466, 472, 479, 486, 493, 501, 508, 515, - 523, 530, 538, 546, 554, 562, 570, 578, - 587, 595, 604, 613, 622, 631, 640, 649, - 659, 668, 678, 688, 698, 708, 718, 729, - 739, 750, 761, 772, 783, 795, 806, 818, - 830, 842, 854, 867, 880, 892, 905, 918, - 932, 945, 959, 973, 987, 1002, 1016, 1031, - 1046, 1061, 1077, 1092, 1108, 1124, 1141, 1157, - 1174, 1191, 1209, 1226, 1244, 1262, 1280, 1299, - 1318, 1337, 1357, 1376, 1396, 1417, 1437, 1458, - 1479, 1501, 1523, 1545, 1567, 1590, 1613, 1637, - 1661, 1685, 1709, 1734, 1760, 1785, 1811, 1837, - 1864, 1891, 1919, 1947, 1975, 2004, 2033, 2062, - 2093, 2123, 2154, 2185, 2217, 2249, 2282, 2315, - 2349, 2383, 2418, 2453, 2489, 2525, 2561, 2599, - 2637, 2675, 2714, 2753, 2793, 2834, 2875, 2917, - 2959, 3003, 3046, 3091, 3135, 3181, 3227, 3274, - 3322, 3370, 3419, 3469, 3520, 3571, 3623, 3675, - 3729, 3783, 3838, 3894, 3951, 4008, 4066, 4125, - 4186, 4246, 4308, 4371, 4434, 4499, 4564, 4631, - 4698, 4766, 4836, 4906, 4978, 5050, 5123, 5198 -}; - - -void CPPlayer::Filter_Control::process() { - - - final_cutoff=it_cutoff; - if (envelope_cutoff>=0) { - - envelope_cutoff=envelope_cutoff*255/64; - final_cutoff=final_cutoff*envelope_cutoff/255; - if (final_cutoff>=0xFF) final_cutoff=0xFE; - - } - -} - -void CPPlayer::Filter_Control::set_filter_parameters(int *p_cutoff,uint8_t *p_reso) { - - - - *p_cutoff=filter_cutoff[final_cutoff]; - *p_reso=it_reso; -} diff --git a/modules/chibi/cp_player_data_nna.cpp b/modules/chibi/cp_player_data_nna.cpp deleted file mode 100644 index 3c50bfb01..000000000 --- a/modules/chibi/cp_player_data_nna.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/*************************************************************************/ -/* cp_player_data_nna.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "cp_player_data.h" - -void CPPlayer::process_NNAs() { - - int i; - - if (!song->has_instruments()) return; - - for (i=0;i<CPPattern::WIDTH;i++) { - - Channel_Control *aux_chn_ctrl = &control.channel[i]; - - if (aux_chn_ctrl->kick==KICK_NOTE) { - - bool k=false; - - if (aux_chn_ctrl->slave_voice!=NULL) { - - Voice_Control *aux_voc_ctrl; - - aux_voc_ctrl=aux_chn_ctrl->slave_voice; - - if (aux_chn_ctrl->instrument_index==aux_chn_ctrl->slave_voice->instrument_index) { //maybe carry - - aux_chn_ctrl->carry.pan=aux_chn_ctrl->slave_voice->panning_envelope_ctrl; - aux_chn_ctrl->carry.vol=aux_chn_ctrl->slave_voice->volume_envelope_ctrl; - aux_chn_ctrl->carry.pitch=aux_chn_ctrl->slave_voice->pitch_envelope_ctrl; - aux_chn_ctrl->carry.maybe=true; - } else - aux_chn_ctrl->carry.maybe=false; - - if (aux_voc_ctrl->NNA_type != CPInstrument::NNA_NOTE_CUT) { - /* Make sure the old MP_VOICE channel knows it has no - master now ! */ - - - - aux_chn_ctrl->slave_voice=NULL; - /* assume the channel is taken by NNA */ - aux_voc_ctrl->has_master_channel=false; - - switch (aux_voc_ctrl->NNA_type) { - case CPInstrument::NNA_NOTE_CONTINUE: { - - } break; - case CPInstrument::NNA_NOTE_OFF: { - - - aux_voc_ctrl->note_end_flags|=END_NOTE_OFF; - - if (!aux_voc_ctrl->volume_envelope_ctrl.active || aux_voc_ctrl->instrument_ptr->get_volume_envelope()->is_loop_enabled()) { - aux_voc_ctrl->note_end_flags|=END_NOTE_FADE; - } - } break; - case CPInstrument::NNA_NOTE_FADE: { - - aux_voc_ctrl->note_end_flags|=END_NOTE_FADE; - } break; - } - } - } - - if (aux_chn_ctrl->duplicate_check_type!=CPInstrument::DCT_DISABLED) { - int i; - - for (i=0;i<control.max_voices;i++) { - if (!mixer->is_voice_active(i)|| - (voice[i].master_channel!=aux_chn_ctrl) || - (aux_chn_ctrl->instrument_index!=voice[i].instrument_index)) - continue; - - Voice_Control *aux_voc_ctrl; - - aux_voc_ctrl=&voice[i]; - - k=false; - switch (aux_chn_ctrl->duplicate_check_type) { - case CPInstrument::DCT_NOTE: - if (aux_chn_ctrl->note==aux_voc_ctrl->note) - k=true; - break; - case CPInstrument::DCT_SAMPLE: - if (aux_chn_ctrl->sample_ptr==aux_voc_ctrl->sample_ptr) - k=true; - break; - case CPInstrument::DCT_INSTRUMENT: - k=true; - break; - } - if (k) { - switch (aux_chn_ctrl->duplicate_check_action) { - case CPInstrument::DCA_NOTE_CUT: { - aux_voc_ctrl->fadeout_volume=0; - } break; - case CPInstrument::DCA_NOTE_OFF: { - - aux_voc_ctrl->note_end_flags|=END_NOTE_OFF; - - if (!aux_voc_ctrl->volume_envelope_ctrl.active || aux_chn_ctrl->instrument_ptr->get_volume_envelope()->is_loop_enabled()) { - - aux_voc_ctrl->note_end_flags|=END_NOTE_FADE; - } - - } break; - case CPInstrument::DCA_NOTE_FADE: { - aux_voc_ctrl->note_end_flags|=END_NOTE_FADE; - } break; - } - } - } - - } - } /* if (aux_chn_ctrl->kick==KICK_NOTE) */ - } -} diff --git a/modules/chibi/cp_player_data_notes.cpp b/modules/chibi/cp_player_data_notes.cpp deleted file mode 100644 index 1bfe24bc2..000000000 --- a/modules/chibi/cp_player_data_notes.cpp +++ /dev/null @@ -1,345 +0,0 @@ -/*************************************************************************/ -/* cp_player_data_notes.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "cp_player_data.h" -#include "cp_sample_manager.h" - -#define RANDOM_MAX 2147483647 - -static inline int32_t cp_random_generate(int32_t *seed) { - int32_t k; - int32_t s = (int32_t)(*seed); - if (s == 0) - s = 0x12345987; - k = s / 127773; - s = 16807 * (s - k * 127773) - 2836 * k; - if (s < 0) - s += 2147483647; - (*seed) = (int32_t)s; - return (int32_t)(s & RANDOM_MAX); -} - - -void CPPlayer::process_new_note(int p_track,uint8_t p_note) { // if there's really a new note.... - - if (control.channel[p_track].real_note!=255) { - control.channel[p_track].old_note=control.channel[p_track].real_note; - - } - - control.channel[p_track].real_note=p_note; - - control.channel[p_track].kick=KICK_NOTE; - - control.channel[p_track].sample_start_index=-1; - control.channel[p_track].sliding=0; - control.channel[p_track].row_has_note=true; - control.channel[p_track].last_event_usecs=song_usecs; - - if (control.channel[p_track].panbrello_type) control.channel[p_track].panbrello_position=0; -} - -bool CPPlayer::process_new_instrument(int p_track,uint8_t p_instrument) { - -// bool different_instrument=false; - ERR_FAIL_INDEX_V(p_instrument,CPSong::MAX_INSTRUMENTS,false); - - if ( song->has_instruments() ) { - - - control.channel[p_track].instrument_ptr=song->get_instrument(p_instrument); - } else { - - control.channel[p_track].instrument_ptr=NULL; - } - - control.channel[p_track].retrig_counter=0; - control.channel[p_track].tremor_position=0; - control.channel[p_track].sample_offset_fine=0; - int old_instr_index=control.channel[p_track].instrument_index; - control.channel[p_track].instrument_index=p_instrument; - - return (old_instr_index!=p_instrument); - - -} - - - // returns if it was able to process -bool CPPlayer::process_note_and_instrument(int p_track,int p_note,int p_instrument) { - - bool aux_result; - aux_result=false; - CPSample *aux_sample=0; // current sample - int dest_sample_index; - bool new_instrument=false; - - control.channel[p_track].row_has_note=false; // wise man says.. "we dont have a note... until we really know we have a note". - control.channel[p_track].new_instrument=false; - - if ( (p_note<0) && (p_instrument<0) ) return aux_result; // nothing to do here - if ( (p_note==255) && (p_instrument==255) ) return aux_result; - - if ( (p_note>=0) && (p_note<120) ) { - - process_new_note(p_track,p_note); - - } else if (p_note==CPNote::CUT) { - - control.channel[p_track].aux_volume=0; - control.channel[p_track].note_end_flags|=END_NOTE_OFF; - control.channel[p_track].note_end_flags|=END_NOTE_KILL; - return aux_result; - - } else if ((p_note==CPNote::OFF) && (song->has_instruments())) { - - if (control.channel[p_track].instrument_ptr!=NULL) { - - control.channel[p_track].note_end_flags|=END_NOTE_OFF; - - if (!control.channel[p_track].instrument_ptr->get_volume_envelope()->is_enabled() || control.channel[p_track].instrument_ptr->get_volume_envelope()->is_loop_enabled()) { - - control.channel[p_track].note_end_flags|=END_NOTE_FADE; - } - } - - return aux_result; - } else return aux_result; // invalid note! - - - if ( (p_instrument>=0) && (p_instrument<CPSong::MAX_INSTRUMENTS)) { - new_instrument=process_new_instrument(p_track,p_instrument); - - if ( song->has_instruments() ) { - // If we're in instrument mode... - if ( control.channel[p_track].instrument_ptr->get_sample_number(control.channel[p_track].real_note) >= CPSong::MAX_SAMPLES) { - - control.channel[p_track].kick=KICK_NOTHING; - return aux_result; - - } else { - dest_sample_index=control.channel[p_track].instrument_ptr->get_sample_number(control.channel[p_track].real_note); - control.channel[p_track].note=control.channel[p_track].instrument_ptr->get_note_number(control.channel[p_track].real_note); - } - - } else { - // If we're in sample mode... - dest_sample_index=control.channel[p_track].instrument_index; - control.channel[p_track].note=control.channel[p_track].real_note; - } - - control.channel[p_track].sample_index=dest_sample_index; - aux_sample=song->get_sample(dest_sample_index); - - if (!CPSampleManager::get_singleton()->check( aux_sample->get_sample_data() )) { - /* INVALID SAMPLE */ - control.channel[p_track].kick=KICK_NOTHING; - return aux_result; - - } - - aux_sample=song->get_sample(dest_sample_index); - } else { - - - if (!control.channel[p_track].sample_ptr) - return aux_result; - - if (song->has_instruments()) { - - if (!control.channel[p_track].instrument_ptr) - return aux_result; - - control.channel[p_track].note=control.channel[p_track].instrument_ptr->get_note_number(control.channel[p_track].real_note); - - } else { - - control.channel[p_track].note=control.channel[p_track].real_note; - - } - - aux_sample=control.channel[p_track].sample_ptr; - - } - - - - if (p_instrument>=CPSong::MAX_INSTRUMENTS && control.channel[p_track].sample_ptr!=aux_sample) { - - control.channel[p_track].new_instrument=(control.channel[p_track].period>0); - } - - control.channel[p_track].sample_ptr=aux_sample; - - /* channel or instrument determined panning ? */ - - control.channel[p_track].panning=control.channel[p_track].channel_panning; - - /* set filter,if any ? */ - - - if (aux_sample->is_pan_enabled()) { - - control.channel[p_track].panning=(int)aux_sample->get_pan()*255/64; - - } else if ( song->has_instruments() && (control.channel[p_track].instrument_ptr->is_pan_default_enabled()) ) { - - control.channel[p_track].panning=(int)control.channel[p_track].instrument_ptr->get_pan_default_amount()*255/64; - } - - - if (song->has_instruments()) { - - - /* Pitch-Pan Separation */ - if ((control.channel[p_track].instrument_ptr->get_pan_pitch_separation()!=0) && (control.channel[p_track].channel_panning!=PAN_SURROUND)){ - - control.channel[p_track].panning+=((control.channel[p_track].real_note-control.channel[p_track].instrument_ptr->get_pan_pitch_center())*control.channel[p_track].instrument_ptr->get_pan_pitch_separation())/8; - - if (control.channel[p_track].panning<PAN_LEFT) control.channel[p_track].panning=PAN_LEFT; - if (control.channel[p_track].panning>PAN_RIGHT) control.channel[p_track].panning=PAN_RIGHT; - } - - /* Random Volume Variation */ - if (control.channel[p_track].instrument_ptr->get_volume_random_variation()>0) { - - control.channel[p_track].random_volume_variation=100-(cp_random_generate(&control.random_seed) % control.channel[p_track].instrument_ptr->get_volume_random_variation()); - - } else { - - control.channel[p_track].random_volume_variation=100; - } - - - /* Random Pan Variation */ - if ((control.channel[p_track].instrument_ptr->get_pan_random_variation()>0) && (control.channel[p_track].panning!=PAN_SURROUND)){ - - int aux_pan_modifier; - - aux_pan_modifier=(cp_random_generate(&control.random_seed) % (control.channel[p_track].instrument_ptr->get_pan_random_variation() << 2)); - if ((cp_random_generate(&control.random_seed) % 2)==1) aux_pan_modifier=0-aux_pan_modifier; /* it's 5am, let me sleep :) */ - - control.channel[p_track].panning+=aux_pan_modifier; - - if (control.channel[p_track].panning<PAN_LEFT) control.channel[p_track].panning=PAN_LEFT; - if (control.channel[p_track].panning>PAN_RIGHT) control.channel[p_track].panning=PAN_RIGHT; - - - } - - /*filter*/ - - if (control.channel[p_track].instrument_ptr->filter_use_default_cutoff()) { - - control.channel[p_track].filter.it_cutoff=control.channel[p_track].instrument_ptr->get_filter_default_cutoff()*2; - - } - - if (control.channel[p_track].instrument_ptr->filter_use_default_resonance()) { - - control.channel[p_track].filter.it_reso=control.channel[p_track].instrument_ptr->get_filter_default_resonance()*2; - - } - - /*envelopes*/ - - - control.channel[p_track].volume_envelope_on=control.channel[p_track].instrument_ptr->get_volume_envelope()->is_enabled(); - control.channel[p_track].panning_envelope_on=control.channel[p_track].instrument_ptr->get_pan_envelope()->is_enabled(); - control.channel[p_track].pitch_envelope_on=control.channel[p_track].instrument_ptr->get_pitch_filter_envelope()->is_enabled(); - control.channel[p_track].NNA_type=control.channel[p_track].instrument_ptr->get_NNA_type(); - control.channel[p_track].duplicate_check_type=control.channel[p_track].instrument_ptr->get_DC_type(); - control.channel[p_track].duplicate_check_action=control.channel[p_track].instrument_ptr->get_DC_action(); - - - } else { - - control.channel[p_track].NNA_type=CPInstrument::NNA_NOTE_CUT; - control.channel[p_track].duplicate_check_type=CPInstrument::DCT_DISABLED; - control.channel[p_track].duplicate_check_action=CPInstrument::DCA_NOTE_CUT; - } - - - if (p_instrument<CPSong::MAX_INSTRUMENTS) { // instrument change - - control.channel[p_track].volume=control.channel[p_track].aux_volume=aux_sample->get_default_volume(); - - } - - - control.channel[p_track].slide_to_period=control.channel[p_track].aux_period=get_period((uint16_t)(control.channel[p_track].note)<<1,CPSampleManager::get_singleton()->get_c5_freq( (aux_sample->get_sample_data()))); - - control.channel[p_track].note_end_flags=END_NOTE_NOTHING; /* clears flags */ - - return true; -} - -void CPPlayer::process_volume_column(int p_track,uint8_t p_volume) { - - control.channel[p_track].current_volume_command=CPNote::EMPTY; - control.channel[p_track].current_volume_parameter=CPNote::EMPTY; - - if (p_volume<65) { // VOLUME - - control.channel[p_track].aux_volume=p_volume; - } else if (p_volume<125) { // Volume Command - - - control.channel[p_track].current_volume_command=(p_volume-65) / 10; - control.channel[p_track].current_volume_parameter=(p_volume-65) % 10; - } else if (p_volume<193) { // PAN - - control.channel[p_track].channel_panning=(p_volume-128)*PAN_RIGHT/64; - control.channel[p_track].panning=control.channel[p_track].channel_panning; - - } else if (p_volume<213) { //More volume Commands - - control.channel[p_track].current_volume_command=((p_volume-193) / 10)+6; - control.channel[p_track].current_volume_parameter=(p_volume-193) % 10; - } -} - - -void CPPlayer::process_note(int p_track,CPNote p_note) { - - if ( p_note.note!=CPNote::SCRIPT ) { - - process_note_and_instrument(p_track,p_note.note,p_note.instrument); - process_volume_column(p_track,p_note.volume); - control.channel[p_track].current_command=p_note.command; - control.channel[p_track].current_parameter=p_note.parameter; - - } else { - - CPNote n = song->get_pattern( control.position.current_pattern )->get_transformed_script_note( p_track, control.position.current_row ); - process_note( p_track, n ); - - song->get_pattern( control.position.current_pattern )->scripted_clone( p_track, control.position.current_row ); - } -} diff --git a/modules/chibi/cp_player_data_utils.cpp b/modules/chibi/cp_player_data_utils.cpp deleted file mode 100644 index 1ee3f30b3..000000000 --- a/modules/chibi/cp_player_data_utils.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/*************************************************************************/ -/* cp_player_data_utils.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "cp_player_data.h" -uint8_t CPPlayer::vibrato_table[32]={ - 0, 24, 49, 74, 97,120,141,161,180,197,212,224,235,244,250,253, - 255,253,250,244,235,224,212,197,180,161,141,120, 97, 74, 49, 24 -}; - -uint8_t CPPlayer::auto_vibrato_table[128]={ - 0, 1, 3, 4, 6, 7, 9,10,12,14,15,17,18,20,21,23, - 24,25,27,28,30,31,32,34,35,36,38,39,40,41,42,44, - 45,46,47,48,49,50,51,52,53,54,54,55,56,57,57,58, - 59,59,60,60,61,61,62,62,62,63,63,63,63,63,63,63, - 64,63,63,63,63,63,63,63,62,62,62,61,61,60,60,59, - 59,58,57,57,56,55,54,54,53,52,51,50,49,48,47,46, - 45,44,42,41,40,39,38,36,35,34,32,31,30,28,27,25, - 24,23,21,20,18,17,15,14,12,10, 9, 7, 6, 4, 3, 1 -}; - - -int8_t CPPlayer::panbrello_table[256]={ - 0, 2, 3, 5, 6, 8, 9, 11, 12, 14, 16, 17, 19, 20, 22, 23, - 24, 26, 27, 29, 30, 32, 33, 34, 36, 37, 38, 39, 41, 42, 43, 44, - 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, - 59, 60, 60, 61, 61, 62, 62, 62, 63, 63, 63, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 63, 63, 63, 62, 62, 62, 61, 61, 60, 60, - 59, 59, 58, 57, 56, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, - 45, 44, 43, 42, 41, 39, 38, 37, 36, 34, 33, 32, 30, 29, 27, 26, - 24, 23, 22, 20, 19, 17, 16, 14, 12, 11, 9, 8, 6, 5, 3, 2, - 0,- 2,- 3,- 5,- 6,- 8,- 9,-11,-12,-14,-16,-17,-19,-20,-22,-23, - -24,-26,-27,-29,-30,-32,-33,-34,-36,-37,-38,-39,-41,-42,-43,-44, - -45,-46,-47,-48,-49,-50,-51,-52,-53,-54,-55,-56,-56,-57,-58,-59, - -59,-60,-60,-61,-61,-62,-62,-62,-63,-63,-63,-64,-64,-64,-64,-64, - -64,-64,-64,-64,-64,-64,-63,-63,-63,-62,-62,-62,-61,-61,-60,-60, - -59,-59,-58,-57,-56,-56,-55,-54,-53,-52,-51,-50,-49,-48,-47,-46, - -45,-44,-43,-42,-41,-39,-38,-37,-36,-34,-33,-32,-30,-29,-27,-26, - -24,-23,-22,-20,-19,-17,-16,-14,-12,-11,- 9,- 8,- 6,- 5,- 3,- 2 -}; - - - - - - -int32_t CPPlayer::get_period(uint16_t p_note,int32_t p_c5speed) { - - if (song->has_linear_slides()) { - - return CPTables::get_linear_period(p_note,0); - } else { - - - return CPTables::get_log_period(p_note>>1,p_c5speed >>1); - } -} - - -int32_t CPPlayer::get_frequency(int32_t period) { - - if (song->has_linear_slides()) { - - return CPTables::get_linear_frequency(period); - } else { - - return CPTables::get_old_frequency(period); - } -} - -int CPPlayer::find_empty_voice() { - - int i; - int min_priority,min_priority_chan=0,priority; - - for (i=0;i<control.max_voices;i++) { - - if ( ((voice[i].kick==KICK_NOTHING)||(voice[i].kick==KICK_ENVELOPE))&&!mixer->is_voice_active(i) ) { - - return i; - - } - } - - // todo more - - for (i=0;i<control.max_voices;i++) { - /* allow us to take over a nonexisting sample */ -// if ((voice[i].s==NULL) -// return k; - - if ((voice[i].kick==KICK_NOTHING)||(voice[i].kick==KICK_ENVELOPE)) { - - priority=voice[i].total_volume<<((CPSampleManager::get_singleton()->get_loop_type( voice[i].sample_ptr->get_sample_data())!=CP_LOOP_NONE)?1:0); - - if ((voice[i].has_master_channel)&&(&voice[i]==voice[i].master_channel->slave_voice)) { - - priority<<=2; - - } - - if ((i==0) || (priority<min_priority)) { - min_priority=priority; - min_priority_chan=i; - } - } - } - - if (min_priority>8000*7) return -1; /* what the fuck is this? */ - - return min_priority_chan; -} - diff --git a/modules/chibi/cp_sample.cpp b/modules/chibi/cp_sample.cpp deleted file mode 100644 index bea883554..000000000 --- a/modules/chibi/cp_sample.cpp +++ /dev/null @@ -1,203 +0,0 @@ -/*************************************************************************/ -/* cp_sample.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "cp_sample.h" - -const char * CPSample::get_name() const { - - return name; -} -void CPSample::set_name(const char *p_name) { - - if (p_name==NULL) { - name[0]=0; - return; - } - - - bool done=false; - for (int i=0;i<NAME_MAX_LEN;i++) { - - - name[i]=done?0:p_name[i]; - if (!done && p_name[i]==0) - done=true; - } - - name[NAME_MAX_LEN-1]=0; /* just in case */ - -} - -void CPSample::set_default_volume(uint8_t p_vol) { - - default_volume=p_vol; -} -uint8_t CPSample::get_default_volume() const{ - - return default_volume; -} - -void CPSample::set_global_volume(uint8_t p_vol) { - - global_volume=p_vol; -} -uint8_t CPSample::get_global_volume() const{ - - return global_volume; -} - -void CPSample::set_pan_enabled(bool p_vol) { - - pan_enabled=p_vol; -} -bool CPSample::is_pan_enabled() const{ - - return pan_enabled; -} - -void CPSample::set_pan(uint8_t p_pan) { - - pan=p_pan; - -} -uint8_t CPSample::get_pan() const{ - - return pan; -} - - -void CPSample::set_vibrato_type(VibratoType p_vibrato_type) { - - vibrato_type=p_vibrato_type; -} -CPSample::VibratoType CPSample::get_vibrato_type() const{ - - return vibrato_type; -} - -void CPSample::set_vibrato_speed(uint8_t p_vibrato_speed) { - - vibrato_speed=p_vibrato_speed; -} -uint8_t CPSample::get_vibrato_speed() const { - - return vibrato_speed; -} - -void CPSample::set_vibrato_depth(uint8_t p_vibrato_depth) { - - vibrato_depth=p_vibrato_depth; -} -uint8_t CPSample::get_vibrato_depth() const{ - - return vibrato_depth; -} - -void CPSample::set_vibrato_rate(uint8_t p_vibrato_rate) { - - vibrato_rate=p_vibrato_rate; -} -uint8_t CPSample::get_vibrato_rate() const{ - - return vibrato_rate; -} - -void CPSample::set_sample_data(CPSample_ID p_ID) { - - id=p_ID; -} -CPSample_ID CPSample::get_sample_data() const{ - - return id; -} - -void CPSample::operator=(const CPSample &p_sample) { - - copy_from(p_sample); -} -void CPSample::copy_from(const CPSample &p_sample) { - - reset(); - set_name(p_sample.get_name()); - - default_volume=p_sample.default_volume; - global_volume=p_sample.global_volume; - - pan_enabled=p_sample.pan_enabled; - pan=p_sample.pan; - - vibrato_type=p_sample.vibrato_type; - vibrato_speed=p_sample.vibrato_speed; - vibrato_depth=p_sample.vibrato_depth; - vibrato_rate=p_sample.vibrato_rate; - - if (CPSampleManager::get_singleton() && !p_sample.id.is_null()) - CPSampleManager::get_singleton()->copy_to( p_sample.id, id ); -} - - - - - -void CPSample::reset() { - - - name[0]=0; - - default_volume=64; - global_volume=64; - - pan_enabled=false; - pan=32; - - vibrato_type=VIBRATO_SINE; - vibrato_speed=0; - vibrato_depth=0; - vibrato_rate=0; - - if (!id.is_null() && CPSampleManager::get_singleton()) - CPSampleManager::get_singleton()->destroy( id ); - - id=CPSample_ID(); - -} - -CPSample::CPSample(const CPSample&p_from) { - - reset(); - copy_from(p_from); -} -CPSample::CPSample() { - - reset(); -} - -CPSample::~CPSample() { - - reset(); -} diff --git a/modules/chibi/cp_sample.h b/modules/chibi/cp_sample.h deleted file mode 100644 index c02b220c8..000000000 --- a/modules/chibi/cp_sample.h +++ /dev/null @@ -1,112 +0,0 @@ -/*************************************************************************/ -/* cp_sample.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef CPSAMPLE_H -#define CPSAMPLE_H - - -#include "cp_config.h" -#include "cp_sample_manager.h" -class CPSample { - -public: - enum VibratoType { - VIBRATO_SINE, - VIBRATO_SAW, - VIBRATO_SQUARE, - VIBRATO_RANDOM - - }; - -private: - - enum { NAME_MAX_LEN=26 }; - - char name[NAME_MAX_LEN]; - - uint8_t default_volume; /* 0.. 64 */ - uint8_t global_volume; /* 0.. 64 */ - - bool pan_enabled; - uint8_t pan; /* 0.. 64 */ - - VibratoType vibrato_type; - uint8_t vibrato_speed; /* 0.. 64 */ - uint8_t vibrato_depth; /* 0.. 64 */ - uint8_t vibrato_rate; /* 0.. 64 */ - - CPSample_ID id; - - void copy_from(const CPSample &p_sample); -public: - - - void operator=(const CPSample &p_sample); - - const char * get_name() const; - void set_name(const char *p_name); - - void set_default_volume(uint8_t p_vol); - uint8_t get_default_volume() const; - - void set_global_volume(uint8_t p_vol); - uint8_t get_global_volume() const; - - void set_pan_enabled(bool p_vol); - bool is_pan_enabled() const; - - void set_pan(uint8_t p_pan); - uint8_t get_pan() const; - - void set_vibrato_type(VibratoType p_vibrato_type); - VibratoType get_vibrato_type() const; - - void set_vibrato_speed(uint8_t p_vibrato_speed) ; - uint8_t get_vibrato_speed() const; - - void set_vibrato_depth(uint8_t p_vibrato_depth); - uint8_t get_vibrato_depth() const; - - void set_vibrato_rate(uint8_t p_vibrato_rate); - uint8_t get_vibrato_rate() const; - - void set_sample_data(CPSample_ID); - CPSample_ID get_sample_data() const; - - void reset(); - - CPSample(const CPSample&p_from); - CPSample(); - ~CPSample(); - -}; - - - - -#endif diff --git a/modules/chibi/cp_sample_defs.h b/modules/chibi/cp_sample_defs.h deleted file mode 100644 index 5ae57aed8..000000000 --- a/modules/chibi/cp_sample_defs.h +++ /dev/null @@ -1,97 +0,0 @@ -/*************************************************************************/ -/* cp_sample_defs.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef CP_SAMPLE_DEFS_H -#define CP_SAMPLE_DEFS_H - -#include "cp_config.h" - -enum CPSample_Loop_Type { - - CP_LOOP_NONE, - CP_LOOP_FORWARD, - CP_LOOP_BIDI -}; - -//#define INVALID_SAMPLE_ID -1 - -#define CP_MIXING_FRAC_BITS_MACRO 13 -#define CP_MIXING_FRAC_BITS_TEXT "13" -// 1<<9 - 1 -#define CP_MIXING_FRAC_BITS_MASK_TEXT "8191" - -enum CPMixConstants { - CP_MIXING_FRAC_BITS=CP_MIXING_FRAC_BITS_MACRO, - CP_MIXING_FRAC_LENGTH=(1<<CP_MIXING_FRAC_BITS), - CP_MIXING_FRAC_MASK=CP_MIXING_FRAC_LENGTH-1, - CP_MIXING_VOL_FRAC_BITS=8, - CP_MIXING_FREQ_FRAC_BITS=8 -}; - -enum CPFilterConstants { - CP_FILTER_SHIFT=16, - CP_FILTER_LENGTH=(1<<CP_FILTER_SHIFT) -}; - - -enum CPInterpolationType { - CP_INTERPOLATION_RAW, - CP_INTERPOLATION_LINEAR, - CP_INTERPOLATION_CUBIC -}; - -enum CPPanConstants { - - CP_PAN_BITS=8, // 0 .. 256 - CP_PAN_LEFT=0, - CP_PAN_RIGHT=((1<<CP_PAN_BITS)-1), // 255 - CP_PAN_CENTER=CP_PAN_RIGHT/2, // 128 - CP_PAN_SURROUND=512 -}; - -enum CPMixerVolConstants { - CP_VOL_MAX=512, - CP_VOL_RAMP_BITS=9, - CP_VOL_SHIFT=2 - - -}; - -enum CPStereoCannels { - CP_CHAN_LEFT, - CP_CHAN_RIGHT -}; - -#define CP_FIRST_SAMPLE_DECLICK_THRESHOLD 1000 -#define CP_FIRST_SAMPLE_RAMP_LEN 32 - -typedef signed char CPFrame8; -typedef signed short CPFrame16; - - -#endif diff --git a/modules/chibi/cp_sample_manager.cpp b/modules/chibi/cp_sample_manager.cpp deleted file mode 100644 index 2ad0a720b..000000000 --- a/modules/chibi/cp_sample_manager.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/*************************************************************************/ -/* cp_sample_manager.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "cp_sample_manager.h" - - -CPSampleManager * CPSampleManager::singleton=NULL; - - -void CPSampleManager::copy_to(CPSample_ID p_from,CPSample_ID &p_to) { - - ERR_FAIL_COND(!check( p_from )); - - - if (p_to.is_null()) { - - p_to=create( is_16bits( p_from), is_stereo( p_from), get_size(p_from)); - } else { - - recreate( p_to, is_16bits( p_from), is_stereo( p_from), get_size(p_from)); - - } - - int len=get_size( p_from ); - int ch=is_stereo( p_from ) ? 2 : 1; - - for (int c=0;c<ch;c++) { - - for (int i=0;i<len;i++) { - - int16_t s=get_data( p_from, i, c ); - set_data( p_to, i, s, c ); - } - } - - set_loop_type( p_to, get_loop_type( p_from ) ); - set_loop_begin( p_to, get_loop_begin( p_from ) ); - set_loop_end( p_to, get_loop_end( p_from ) ); - set_c5_freq( p_to, get_c5_freq( p_from ) ); - - - -} - -CPSampleManager::CPSampleManager() { - - singleton=this; -} - -CPSampleManager *CPSampleManager::get_singleton() { - - return singleton; -} diff --git a/modules/chibi/cp_sample_manager.h b/modules/chibi/cp_sample_manager.h deleted file mode 100644 index b6d47a301..000000000 --- a/modules/chibi/cp_sample_manager.h +++ /dev/null @@ -1,99 +0,0 @@ -/*************************************************************************/ -/* cp_sample_manager.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef CP_SAMPLE_MANAGER_H -#define CP_SAMPLE_MANAGER_H - -#include "cp_config.h" -#include "cp_sample_defs.h" - - - -/** -@author Juan Linietsky -*/ - - -/* abstract base CPSample_ID class */ - -struct CPSample_ID { - - void *_private; - - bool operator==(const CPSample_ID&p_other) const { return _private==p_other._private; } - bool operator!=(const CPSample_ID&p_other) const { return _private!=p_other._private; } - bool is_null() const { return _private==0; } - CPSample_ID(void *p_private=0) { _private=p_private; }; -}; - - -class CPSampleManager { - - static CPSampleManager * singleton; - -public: - - /* get the singleton instance */ - static CPSampleManager *get_singleton(); - - virtual void copy_to(CPSample_ID p_from,CPSample_ID &p_to); ///< if p_to is null, it gets created - - virtual CPSample_ID create(bool p_16bits,bool p_stereo,int32_t p_len)=0; - virtual void recreate(CPSample_ID p_id,bool p_16bits,bool p_stereo,int32_t p_len)=0; - virtual void destroy(CPSample_ID p_id)=0; - virtual bool check(CPSample_ID p_id)=0; // return false if invalid - - virtual void set_c5_freq(CPSample_ID p_id,int32_t p_freq)=0; - virtual void set_loop_begin(CPSample_ID p_id,int32_t p_begin)=0; - virtual void set_loop_end(CPSample_ID p_id,int32_t p_end)=0; - virtual void set_loop_type(CPSample_ID p_id,CPSample_Loop_Type p_type)=0; - virtual void set_chunk(CPSample_ID p_id,int32_t p_index,void *p_data,int p_data_len)=0; - - - virtual int32_t get_loop_begin(CPSample_ID p_id)=0; - virtual int32_t get_loop_end(CPSample_ID p_id)=0; - virtual CPSample_Loop_Type get_loop_type(CPSample_ID p_id)=0; - virtual int32_t get_c5_freq(CPSample_ID p_id)=0; - virtual int32_t get_size(CPSample_ID p_id)=0; - virtual bool is_16bits(CPSample_ID p_id)=0; - virtual bool is_stereo(CPSample_ID p_id)=0; - virtual bool lock_data(CPSample_ID p_id)=0; - virtual void *get_data(CPSample_ID p_id)=0; /* WARNING: Not all sample managers -may be able to implement this, it depends on the mixer in use! */ - virtual int16_t get_data(CPSample_ID p_id, int p_sample, int p_channel=0)=0; /// Does not need locking - virtual void set_data(CPSample_ID p_id, int p_sample, int16_t p_data,int p_channel=0)=0; /// Does not need locking - virtual void unlock_data(CPSample_ID p_id)=0; - - virtual void get_chunk(CPSample_ID p_id,int32_t p_index,void *p_data,int p_data_len)=0; - - CPSampleManager(); - virtual ~CPSampleManager(){} - -}; - -#endif diff --git a/modules/chibi/cp_song.cpp b/modules/chibi/cp_song.cpp deleted file mode 100644 index 197e44f69..000000000 --- a/modules/chibi/cp_song.cpp +++ /dev/null @@ -1,957 +0,0 @@ -/*************************************************************************/ -/* cp_song.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "cp_song.h" - -void CPSong::set_name(const char *p_name) { - - if (p_name==NULL) { - variables.name[0]=0; - return; - } - - - bool done=false; - for (int i=0;i<MAX_SONG_NAME;i++) { - - - variables.name[i]=done?0:p_name[i]; - if (!done && p_name[i]==0) - done=true; - } - - variables.name[MAX_SONG_NAME-1]=0; /* just in case */ -} - -const char * CPSong::get_name() { - - return variables.name; - -} - -void CPSong::set_message(const char *p_message) { - - if (p_message==NULL) { - variables.message[0]=0; - return; - } - - bool done=false; - for (int i=0;i<MAX_MESSAGE_LEN;i++) { - - - variables.message[i]=done?0:p_message[i]; - if (!done && p_message[i]==0) - done=true; - } - - variables.message[MAX_MESSAGE_LEN-1]=0; /* just in case */ -} - -const char * CPSong::get_message() { - - return variables.message; - -} - -void CPSong::set_row_highlight_minor(int p_hl_minor) { - - variables.row_highlight_minor=p_hl_minor; -} -int CPSong::get_row_highlight_minor() { - - return variables.row_highlight_minor; -} - -void CPSong::set_row_highlight_major(int p_hl_major) { - - variables.row_highlight_major=p_hl_major; - - -} /* 0 .. 256 */ -int CPSong::get_row_highlight_major() { - - return variables.row_highlight_major; - - -} /* 0 .. 256 */ - -void CPSong::set_mixing_volume(int p_mix_volume) { - - - variables.mixing_volume=p_mix_volume; -} /* 0 .. 128 */ -int CPSong::get_mixing_volume() { - - return variables.mixing_volume; - -} /* 0 .. 128 */ - -void CPSong::set_global_volume(int p_global_volume) { - - - initial_variables.global_volume=p_global_volume; - -} /* 0 .. 128 */ -int CPSong::get_global_volume() { - - return initial_variables.global_volume; - -} /* 0 .. 128 */ - -void CPSong::set_stereo_separation(int p_separation) { - - variables.stereo_separation=p_separation; - -} /* 0 .. 128 */ -int CPSong::get_stereo_separation() { - - return variables.stereo_separation; -} /* 0 .. 128 */ - -void CPSong::set_stereo(bool p_stereo) { - - variables.use_stereo=p_stereo; - -} -bool CPSong::is_stereo() { - - return variables.use_stereo; -} - -void CPSong::set_instruments(bool p_instruments) { - - variables.use_instruments=p_instruments; - - -} -bool CPSong::has_instruments() { - - - return variables.use_instruments; - -} - -void CPSong::set_linear_slides(bool p_linear_slides) { - - variables.use_linear_slides=p_linear_slides; - - -} -bool CPSong::has_linear_slides() { - - return variables.use_linear_slides; - - -} - -void CPSong::set_old_effects(bool p_old_effects) { - - variables.old_effects=p_old_effects; - - -} -bool CPSong::has_old_effects() { - - return variables.old_effects; -} - -void CPSong::set_compatible_gxx(bool p_compatible_gxx) { - - - variables.compatible_gxx=p_compatible_gxx; -} -bool CPSong::has_compatible_gxx() { - - return variables.compatible_gxx; - -} - -void CPSong::set_speed(int p_speed) { - - CP_ERR_COND(p_speed<MIN_SPEED); - CP_ERR_COND(p_speed>MAX_SPEED); - - initial_variables.speed=p_speed; - -} /* 1 .. 255 */ -int CPSong::get_speed() { - - return initial_variables.speed; - -} /* 1 .. 255 */ - -void CPSong::set_tempo(int p_tempo) { - - CP_ERR_COND( p_tempo<MIN_TEMPO ); - CP_ERR_COND( p_tempo>MAX_TEMPO ); - - initial_variables.tempo=p_tempo; - -} /* MIN_TEMPO .. MAX_TEMPO */ -int CPSong::get_tempo() { - - return initial_variables.tempo; - - -} /* MIN_TEMPO .. MAX_TEMPO */ - -void CPSong::set_channel_pan(int p_channel,int p_pan) { - - CP_FAIL_INDEX(p_channel,CPPattern::WIDTH); - CP_FAIL_INDEX(p_pan,CHANNEL_MAX_PAN+1); - - initial_variables.channel[p_channel].pan=p_pan; - -} /* 0 .. CHANNEL_MAX_PAN */ -int CPSong::get_channel_pan(int p_channel) { - - CP_FAIL_INDEX_V(p_channel,CPPattern::WIDTH,-1); - - return initial_variables.channel[p_channel].pan; -} - -void CPSong::set_channel_volume(int p_channel,int p_volume) { - - CP_FAIL_INDEX(p_channel,CPPattern::WIDTH); - CP_FAIL_INDEX(p_volume,CHANNEL_MAX_VOLUME+1); - - - initial_variables.channel[p_channel].volume=p_volume; - - -} /* 0 .. CHANNEL_MAX_VOLUME */ - - -int CPSong::get_channel_volume(int p_channel) { - - CP_FAIL_INDEX_V(p_channel,CPPattern::WIDTH,-1); - - return initial_variables.channel[p_channel].volume; - -} - -void CPSong::set_channel_chorus(int p_channel,int p_chorus) { - - CP_FAIL_INDEX(p_channel,CPPattern::WIDTH); - CP_FAIL_INDEX(p_chorus,CHANNEL_MAX_CHORUS+1); - - - initial_variables.channel[p_channel].chorus=p_chorus; - - -} /* 0 .. CHANNEL_MAX_CHORUS */ - - -int CPSong::get_channel_chorus(int p_channel) { - - CP_FAIL_INDEX_V(p_channel,CPPattern::WIDTH,-1); - - return initial_variables.channel[p_channel].chorus; - -} - -void CPSong::set_channel_reverb(int p_channel,int p_reverb) { - - CP_FAIL_INDEX(p_channel,CPPattern::WIDTH); - CP_FAIL_INDEX(p_reverb,CHANNEL_MAX_REVERB+1); - - - initial_variables.channel[p_channel].reverb=p_reverb; - - -} /* 0 .. CHANNEL_MAX_CHORUS */ - - -int CPSong::get_channel_reverb(int p_channel) { - - CP_FAIL_INDEX_V(p_channel,CPPattern::WIDTH,-1); - - return initial_variables.channel[p_channel].reverb; - -} - -void CPSong::set_channel_surround(int p_channel,bool p_surround) { - - CP_FAIL_INDEX(p_channel,CPPattern::WIDTH); - initial_variables.channel[p_channel].surround=p_surround; - -} -bool CPSong::is_channel_surround(int p_channel) { - - CP_FAIL_INDEX_V(p_channel,CPPattern::WIDTH,false); - - return initial_variables.channel[p_channel].surround; - - -} - -void CPSong::set_channel_mute(int p_channel,bool p_mute) { - - CP_FAIL_INDEX(p_channel,CPPattern::WIDTH); - - initial_variables.channel[p_channel].mute=p_mute; - -} -bool CPSong::is_channel_mute(int p_channel) { - - CP_FAIL_INDEX_V(p_channel,CPPattern::WIDTH,false); - - return initial_variables.channel[p_channel].mute; - -} - -/* arrays of stuff */ - -CPPattern* CPSong::get_pattern(int p_pattern) { - - CP_FAIL_INDEX_V(p_pattern,MAX_PATTERNS, NULL); - - return &pattern[p_pattern]; - -} -CPSample* CPSong::get_sample(int p_sample) { - - CP_FAIL_INDEX_V(p_sample,MAX_SAMPLES,NULL); - - return &sample[p_sample]; - - -} -CPInstrument* CPSong::get_instrument(int p_instrument) { - - - CP_FAIL_INDEX_V(p_instrument,MAX_INSTRUMENTS,NULL); - - return &instrument[p_instrument]; - -} - -int CPSong::get_order(int p_order) { - - CP_FAIL_INDEX_V(p_order,MAX_ORDERS,CP_ORDER_NONE); - - - return order[p_order]; - -} -void CPSong::set_order(int p_order,int p_pattern) { - - CP_FAIL_INDEX(p_order,MAX_ORDERS); - - order[p_order]=p_pattern; - -} - - -void CPSong::clear_instrument_with_samples(int p_instrument) { - - CPInstrument *ins = get_instrument( p_instrument ); - if (!ins) - return; - - for (int i=0;i<CPNote::NOTES;i++) { - - CPSample *s=get_sample( ins->get_sample_number( i ) ); - - if (!s) - continue; - - if (s->get_sample_data().is_null()) - continue; - - s->reset(); - } - ins->reset(); -} - -void CPSong::make_instrument_from_sample(int p_sample) { - - if (!has_instruments()) - return; - CP_ERR_COND(!get_sample( p_sample )); - - for (int i=0;i<MAX_INSTRUMENTS;i++) { - - - CPInstrument *ins=get_instrument(i); - - bool empty_slot=true; - for (int n=0;n<CPNote::NOTES;n++) { - - if (ins->get_sample_number(n)<MAX_SAMPLES) { - - empty_slot=false; - break; - } - } - - if (!empty_slot) - continue; - - for (int n=0;n<CPNote::NOTES;n++) { - - ins->set_sample_number(n,p_sample); - ins->set_note_number(n,n); - } - - ins->set_name( get_sample( p_sample )->get_name() ); - break; - } - -} - -void CPSong::make_instruments_from_samples() { - - for (int i=0;i<MAX_SAMPLES;i++) { - - CPInstrument *ins=get_instrument( i ); - - if (!ins) - continue; - - ins->reset(); - - CPSample *s=get_sample( i ); - - if (!s) - continue; - - ins->set_name( s->get_name() ); - - if (s->get_sample_data().is_null()) - continue; - - - - - for(int j=0;j<CPNote::NOTES;j++) - ins->set_sample_number( j, i ); - - - - } -} - -void CPSong::reset(bool p_clear_patterns,bool p_clear_samples,bool p_clear_instruments,bool p_clear_variables) { - - if (p_clear_variables) { - variables.name[0]=0; - variables.message[0]=0; - variables.row_highlight_major=16; - variables.row_highlight_minor=4; - variables.mixing_volume=48; - variables.old_effects=false; - if (p_clear_instruments) //should not be cleared, if not clearing instruments!! - variables.use_instruments=false; - variables.stereo_separation=128; - variables.use_linear_slides=true; - variables.use_stereo=true; - - initial_variables.global_volume=128; - initial_variables.speed=6; - initial_variables.tempo=125; - - for (int i=0;i<CPPattern::WIDTH;i++) { - - initial_variables.channel[i].pan=32; - initial_variables.channel[i].volume=CHANNEL_MAX_VOLUME; - initial_variables.channel[i].mute=false; - initial_variables.channel[i].surround=false; - initial_variables.channel[i].chorus=0; - initial_variables.channel[i].reverb=0; - - } - - effects.chorus.delay_ms=6; - effects.chorus.separation_ms=3; - effects.chorus.depth_ms10=6, - effects.chorus.speed_hz10=5; - effects.reverb_mode=REVERB_MODE_ROOM; - } - - if (p_clear_samples) { - for (int i=0;i<MAX_SAMPLES;i++) - get_sample(i)->reset(); - } - - if (p_clear_instruments) { - for (int i=0;i<MAX_INSTRUMENTS;i++) - get_instrument(i)->reset(); - } - - if (p_clear_patterns) { - for (int i=0;i<MAX_PATTERNS;i++) - get_pattern(i)->clear(); - - for (int i=0;i<MAX_ORDERS;i++) - set_order( i, CP_ORDER_NONE ); - } - - -} - - -CPSong::ReverbMode CPSong::get_reverb_mode() { - - return effects.reverb_mode; -} -void CPSong::set_reverb_mode(ReverbMode p_mode) { - - effects.reverb_mode=p_mode; -} - -void CPSong::set_chorus_delay_ms(int p_amount) { - - effects.chorus.delay_ms=p_amount; -} -void CPSong::set_chorus_separation_ms(int p_amount) { - - effects.chorus.separation_ms=p_amount; - -} -void CPSong::set_chorus_depth_ms10(int p_amount) { - - effects.chorus.depth_ms10=p_amount; - -} -void CPSong::set_chorus_speed_hz10(int p_amount) { - - effects.chorus.speed_hz10=p_amount; - -} - -int CPSong::get_chorus_delay_ms() { - - return effects.chorus.delay_ms; - -} -int CPSong::get_chorus_separation_ms() { - - return effects.chorus.separation_ms; -} -int CPSong::get_chorus_depth_ms10() { - - return effects.chorus.depth_ms10; - -} -int CPSong::get_chorus_speed_hz10() { - - return effects.chorus.speed_hz10; - -} - -void CPSong::cleanup_unused_patterns() { - - for (int i=0;i<MAX_PATTERNS;i++) { - - bool used=false; - if (get_pattern(i)->is_empty()) - continue; - - for (int j=0;j<MAX_ORDERS;j++) { - - if (get_order(j)==i) { - used=true; - - } - } - - if (!used) - get_pattern(i)->clear(); - } - -} -void CPSong::cleanup_unused_instruments(){ - - if (!has_instruments()) - return; - - bool instr_found[MAX_INSTRUMENTS]; - for (int i=0;i<MAX_INSTRUMENTS;i++) - instr_found[i]=false; - - for (int i=0;i<MAX_PATTERNS;i++) { - - if (get_pattern(i)->is_empty()) - continue; - - for (int row=0;row<get_pattern(i)->get_length();row++) { - - - for (int col=0;col<CPPattern::WIDTH;col++) { - - CPNote n; - n=get_pattern(i)->get_note( col,row ); - - if (n.instrument<MAX_INSTRUMENTS) - instr_found[n.instrument]=true; - - } - - } - - } - - for (int i=0;i<MAX_INSTRUMENTS;i++) - if (!instr_found[i]) - get_instrument(i)->reset(); - - -} -void CPSong::cleanup_unused_samples(){ - - if (!has_instruments()) - return; - - bool sample_found[MAX_SAMPLES]; - for (int i=0;i<MAX_INSTRUMENTS;i++) - sample_found[i]=false; - - for (int i=0;i<MAX_PATTERNS;i++) { - - if (get_pattern(i)->is_empty()) - continue; - - - for (int row=0;row<get_pattern(i)->get_length();row++) { - - - for (int col=0;col<CPPattern::WIDTH;col++) { - - CPNote n; - n=get_pattern(i)->get_note( col,row ); - - if (n.instrument>=MAX_SAMPLES) - continue; - - if (has_instruments()) { - - for (int nt=0;nt<CPNote::NOTES;nt++) { - - int smp=get_instrument(n.instrument)->get_sample_number(nt); - if (smp<MAX_SAMPLES) - sample_found[smp]=true; - } - - } else { - if (n.instrument<MAX_SAMPLES) - sample_found[n.instrument]=true; - } - - } - - } - - } - - for (int i=0;i<MAX_SAMPLES;i++) - if (!sample_found[i]) - get_sample(i)->reset(); - -} -void CPSong::cleanup_unused_orders(){ - - bool finito=false; - for (int j=0;j<MAX_ORDERS;j++) { - - - if (get_order(j)==CP_ORDER_NONE) - finito=true; - if (finito) - set_order(j,CP_ORDER_NONE); - - } - -} - -void CPSong::clear_all_default_pan() { - - for (int i=0;i<MAX_INSTRUMENTS;i++) - get_instrument(i)->set_pan_default_enabled( false ); //die! - - for (int i=0;i<MAX_SAMPLES;i++) - get_sample(i)->set_pan_enabled( false ); //die! - -} - - -void CPSong::clear_all_default_vol(){ - - for (int i=0;i<MAX_SAMPLES;i++) - get_sample(i)->set_default_volume( 64 ); //die! - for (int i=0;i<MAX_INSTRUMENTS;i++) - get_instrument(i)->set_volume_global_amount( CPInstrument::MAX_VOLUME ); - -} - - -int CPSong::get_order_in_use_count() { - - - int order_count = 0; - - for (int i=(MAX_ORDERS-1);i>=0;i--) { - - - if (get_order(i)!=CP_ORDER_NONE) { - order_count=i+1; - break; - } - } - - return order_count; -} -int CPSong::get_pattern_in_use_count() { - - - int pattern_count=0; - - for (int i=(CPSong::MAX_PATTERNS-1);i>=0;i--) { - - - if (!get_pattern(i)->is_empty()) { - pattern_count=i+1; - break; - } - } - - return pattern_count; -} - -int CPSong::get_instrument_in_use_count() { - - int instrument_count=0; - - for (int i=(CPSong::MAX_INSTRUMENTS-1);i>=0;i--) { - - CPInstrument *ins = get_instrument(i); - bool in_use=false; - - for (int s = 0 ; s < CPNote::NOTES ; s++ ) { - - int smp_idx = ins->get_sample_number(s); - if (smp_idx<0 || smp_idx>=CPSong::MAX_SAMPLES) - continue; - - if (!get_sample(smp_idx)->get_sample_data().is_null()) { - in_use=true; - break; - } - - } - - if (in_use) { - instrument_count=i+1; - break; - } - } - - return instrument_count; -} -#include <stdio.h> -int CPSong::get_channels_in_use() { - - int max=0; - - for (int p=0;p<CPSong::MAX_PATTERNS;p++) { - - CPPattern *pat = get_pattern(p); - if (pat->is_empty()) - continue; - - - for (int c=(CPPattern::WIDTH-1);c>=0;c--) { - - if (c<max) - break; - - bool has_note=false; - for (int r=0;r<pat->get_length();r++) { - - CPNote n = pat->get_note( c, r ); - if (!n.is_empty()) { - has_note=true; - break; - } - } - - if (has_note) { - - max=c+1; - } - } - } - - return max; -} - - -void CPSong::separate_in_one_sample_instruments(int p_instrument) { - - CP_ERR_COND( !variables.use_instruments ); - CP_FAIL_INDEX( p_instrument, MAX_INSTRUMENTS ); - - int remapped_count=0; - - signed char remap[MAX_SAMPLES]; - - for (int i=0;i<MAX_SAMPLES;i++) { - - remap[i]=-1; - } - - /* Find remaps */ - CPInstrument *ins=get_instrument(p_instrument); - for (int i=0;i<CPNote::NOTES;i++) { - - int sn = ins->get_sample_number(i); - - // check for unusable sample - if (sn<0 || sn>=MAX_SAMPLES || get_sample(sn)->get_sample_data().is_null()) - continue; - printf("sample %i\n",sn); - if ( remap[sn] !=-1 ) { - printf("already mapped to %i\n",remap[sn]); - continue; - } - - printf("isn't remapped\n"); - - // find remap - - for (int j=0;j<MAX_INSTRUMENTS;j++) { - - if (!get_instrument(j)->is_empty()) - continue; - - printf("map to %i\n",j); - - //copy - *get_instrument(j)=*ins; - - // assign samples - for (int k=0;k<CPNote::NOTES;k++) { - - get_instrument(j)->set_note_number(k,k); - get_instrument(j)->set_sample_number(k,sn); - } - remap[sn]=j; - remapped_count++; - break; - } - - CP_ERR_COND(remap[sn]==-1); // no more free instruments - } - - printf("remapped %i\n",remapped_count); - - if (remapped_count<2) { - //undo if only one is remapped - for (int i=0;i<MAX_SAMPLES;i++) { - - if (remap[i]!=-1) { - - get_instrument(remap[i])->reset(); - } - } - return; - } - - /* remap all song */ - - for (int p=0;p<CPSong::MAX_PATTERNS;p++) { - - CPPattern *pat = get_pattern(p); - if (pat->is_empty()) - continue; - - - for (int c=0;c<CPPattern::WIDTH;c++) { - - for (int r=0;r<pat->get_length();r++) { - - CPNote n = pat->get_note(c,r); - if (n.note<CPNote::NOTES && n.instrument==p_instrument) { - - int sn = ins->get_sample_number(n.note); - if (remap[sn]==-1) - pat->set_note(c,r,CPNote()); - else { - - n.instrument=remap[sn]; - pat->set_note(c,r,n); - } - } - } - } - } - - ins->reset(); - -} - - -CPSong::CPSong() { - - reset(); -} -CPSong::~CPSong() { - -} - - - - -int get_song_next_order_idx(CPSong *p_song, int p_order_idx) { - - int baseorder,order_counter; - - order_counter=-1; - - baseorder=p_order_idx; - - do { - - baseorder++; - if ( baseorder>(CPSong::MAX_ORDERS-1) ) baseorder=0; - order_counter++; - - } while ( (p_song->get_order(baseorder)>=(CPSong::MAX_PATTERNS) ) && (order_counter<CPSong::MAX_ORDERS) ); - - - if (order_counter==CPSong::MAX_ORDERS) { - - return -1; - - } else { - - return baseorder; - } - -} diff --git a/modules/chibi/cp_song.h b/modules/chibi/cp_song.h deleted file mode 100644 index ba0fa3e80..000000000 --- a/modules/chibi/cp_song.h +++ /dev/null @@ -1,261 +0,0 @@ -/*************************************************************************/ -/* cp_song.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef CPSONG_H -#define CPSONG_H - - -/**CPSong Class - *@author Juan Linietsky - */ - -#include "cp_order.h" -#include "cp_pattern.h" -#include "cp_sample.h" -#include "cp_instrument.h" - -class CPSong { -public: - enum { - MAX_SONG_NAME=26, - MAX_ORDERS=200, - MAX_PATTERNS=200, - MAX_SAMPLES=99, - MAX_INSTRUMENTS=99, - - CHANNEL_MAX_PAN=64, - CHANNEL_MAX_VOLUME=64, - CHANNEL_MAX_CHORUS=64, - CHANNEL_MAX_REVERB=64, - - MIN_TEMPO=31, - MAX_TEMPO=255, - MIN_SPEED=1, - MAX_SPEED=255, - MAX_MESSAGE_LEN=8000, - - - - }; - - enum ReverbMode { - REVERB_MODE_ROOM, - REVERB_MODE_STUDIO_SMALL, - REVERB_MODE_STUDIO_MEDIUM, - REVERB_MODE_STUDIO_LARGE, - REVERB_MODE_HALL, - REVERB_MODE_SPACE_ECHO, - REVERB_MODE_ECHO, - REVERB_MODE_DELAY, - REVERB_MODE_HALF_ECHO - }; - -private: - CPOrder order[MAX_ORDERS]; - CPPattern pattern[MAX_PATTERNS]; - CPSample sample[MAX_SAMPLES]; - CPInstrument instrument[MAX_INSTRUMENTS]; - - - - struct Song_Variables { // variables that wont change in playback - - char name[MAX_SONG_NAME]; - char message[MAX_MESSAGE_LEN]; - /* string message; */ - - int row_highlight_minor; - int row_highlight_major; - - int mixing_volume; - int stereo_separation; - - bool use_stereo; - bool use_instruments; - bool use_linear_slides; - - bool old_effects; - bool compatible_gxx; - - } variables; - - struct Initial_Variables { // Initial values used for playback - - struct Channel_State { - - int pan,volume; // 0-- CHANNEL_MAX_PAN, CHANNEL_MAX_VOLUME - bool surround; - bool mute; - int chorus; //0 - 64 - int reverb; //0 - 64 - }; - - int global_volume; - int speed; - int tempo; - - Channel_State channel[CPPattern::WIDTH]; - } initial_variables; - - struct Effects { - - ReverbMode reverb_mode; - - struct Chorus { - - int delay_ms; - int separation_ms; - int depth_ms10; - int speed_hz10; - } chorus; - - } effects; - -public: - - /* Properties */ - - const char *get_name(); - void set_name(const char *p_name); - - const char *get_message(); - void set_message(const char *p_message); - - void set_row_highlight_minor(int p_hl_minor); /* 0 .. 256 */ - int get_row_highlight_minor(); /* 0 .. 256 */ - - void set_row_highlight_major(int p_hl_major); /* 0 .. 256 */ - int get_row_highlight_major(); /* 0 .. 256 */ - - void set_mixing_volume(int p_mix_volume); /* 0 .. 128 */ - int get_mixing_volume(); /* 0 .. 128 */ - - void set_global_volume(int p_global_volume); /* 0 .. 128 */ - int get_global_volume(); /* 0 .. 128 */ - - void set_stereo_separation(int p_separation); /* 0 .. 128 */ - int get_stereo_separation(); /* 0 .. 128 */ - - void set_stereo(bool p_stereo); - bool is_stereo(); - - void set_instruments(bool p_instruments); - bool has_instruments(); - - void set_linear_slides(bool p_linear_slides); - bool has_linear_slides(); - - void set_old_effects(bool p_old_effects); - bool has_old_effects(); - - void set_compatible_gxx(bool p_compatible_gxx); - bool has_compatible_gxx(); - - void set_speed(int p_speed); /* 1 .. 255 */ - int get_speed(); /* 1 .. 255 */ - - void set_tempo(int p_tempo); /* 31 .. 255 */ - int get_tempo(); /* 31 .. 255 */ - - void set_channel_pan(int p_channel,int p_pan); /* 0 .. 64 */ - int get_channel_pan(int p_channel); - - void set_channel_volume(int p_channel,int p_volume); /* 0 .. 64 */ - int get_channel_volume(int p_channel); - - void set_channel_surround(int p_channel,bool p_surround); - bool is_channel_surround(int p_channel); - - void set_channel_mute(int p_channel,bool p_mute); - bool is_channel_mute(int p_channel); - - void set_channel_chorus(int p_channel,int p_chorus); /* 0 .. 64 */ - int get_channel_chorus(int p_channel); - - void set_channel_reverb(int p_channel,int p_reverb); /* 0 .. 64 */ - int get_channel_reverb(int p_channel); - - /* arrays of stuff */ - - CPPattern* get_pattern(int p_pattern); - CPSample* get_sample(int p_sample); - CPInstrument* get_instrument(int p_instrument); - - int get_order(int p_position); - void set_order(int p_position,int p_order); - - - /* Effects */ - - ReverbMode get_reverb_mode(); - void set_reverb_mode(ReverbMode p_mode); - - void set_chorus_delay_ms(int p_amount); - void set_chorus_separation_ms(int p_amount); - void set_chorus_depth_ms10(int p_amount); - void set_chorus_speed_hz10(int p_amount); - - int get_chorus_delay_ms(); - int get_chorus_separation_ms(); - int get_chorus_depth_ms10(); - int get_chorus_speed_hz10(); - - /* utils */ - - void reset(bool p_clear_patterns=true,bool p_clear_samples=true,bool p_clear_instruments=true,bool p_clear_variables=true); - - void cleanup_unused_patterns(); - void cleanup_unused_instruments(); - void cleanup_unused_samples(); - void cleanup_unused_orders(); - void clear_all_default_pan(); - void clear_all_default_vol(); - - void clear_instrument_with_samples(int p_instrument); - - void make_instruments_from_samples(); - void make_instrument_from_sample(int p_sample); - - void separate_in_one_sample_instruments(int p_instrument); - - int get_order_in_use_count(); - int get_pattern_in_use_count(); - int get_instrument_in_use_count(); - int get_channels_in_use(); - - CPSong(); - ~CPSong(); - -}; - - -/* Some helper for something used a lot */ - -int get_song_next_order_idx(CPSong *p_song, int p_order_idx); - -#endif diff --git a/modules/chibi/cp_tables.cpp b/modules/chibi/cp_tables.cpp deleted file mode 100644 index a7ed34ff3..000000000 --- a/modules/chibi/cp_tables.cpp +++ /dev/null @@ -1,254 +0,0 @@ -/*************************************************************************/ -/* cp_tables.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "cp_tables.h" - -int32_t CPTables::linear_period_to_freq_tab[768]={ - - 535232,534749,534266,533784,533303,532822,532341,531861, - 531381,530902,530423,529944,529466,528988,528511,528034, - 527558,527082,526607,526131,525657,525183,524709,524236, - 523763,523290,522818,522346,521875,521404,520934,520464, - 519994,519525,519057,518588,518121,517653,517186,516720, - 516253,515788,515322,514858,514393,513929,513465,513002, - 512539,512077,511615,511154,510692,510232,509771,509312, - 508852,508393,507934,507476,507018,506561,506104,505647, - 505191,504735,504280,503825,503371,502917,502463,502010, - 501557,501104,500652,500201,499749,499298,498848,498398, - 497948,497499,497050,496602,496154,495706,495259,494812, - 494366,493920,493474,493029,492585,492140,491696,491253, - 490809,490367,489924,489482,489041,488600,488159,487718, - 487278,486839,486400,485961,485522,485084,484647,484210, - 483773,483336,482900,482465,482029,481595,481160,480726, - 480292,479859,479426,478994,478562,478130,477699,477268, - 476837,476407,475977,475548,475119,474690,474262,473834, - 473407,472979,472553,472126,471701,471275,470850,470425, - 470001,469577,469153,468730,468307,467884,467462,467041, - 466619,466198,465778,465358,464938,464518,464099,463681, - 463262,462844,462427,462010,461593,461177,460760,460345, - 459930,459515,459100,458686,458272,457859,457446,457033, - 456621,456209,455797,455386,454975,454565,454155,453745, - 453336,452927,452518,452110,451702,451294,450887,450481, - 450074,449668,449262,448857,448452,448048,447644,447240, - 446836,446433,446030,445628,445226,444824,444423,444022, - 443622,443221,442821,442422,442023,441624,441226,440828, - 440430,440033,439636,439239,438843,438447,438051,437656, - 437261,436867,436473,436079,435686,435293,434900,434508, - 434116,433724,433333,432942,432551,432161,431771,431382, - 430992,430604,430215,429827,429439,429052,428665,428278, - 427892,427506,427120,426735,426350,425965,425581,425197, - 424813,424430,424047,423665,423283,422901,422519,422138, - 421757,421377,420997,420617,420237,419858,419479,419101, - 418723,418345,417968,417591,417214,416838,416462,416086, - 415711,415336,414961,414586,414212,413839,413465,413092, - 412720,412347,411975,411604,411232,410862,410491,410121, - 409751,409381,409012,408643,408274,407906,407538,407170, - 406803,406436,406069,405703,405337,404971,404606,404241, - 403876,403512,403148,402784,402421,402058,401695,401333, - 400970,400609,400247,399886,399525,399165,398805,398445, - 398086,397727,397368,397009,396651,396293,395936,395579, - 395222,394865,394509,394153,393798,393442,393087,392733, - 392378,392024,391671,391317,390964,390612,390259,389907, - 389556,389204,388853,388502,388152,387802,387452,387102, - 386753,386404,386056,385707,385359,385012,384664,384317, - 383971,383624,383278,382932,382587,382242,381897,381552, - 381208,380864,380521,380177,379834,379492,379149,378807, - 378466,378124,377783,377442,377102,376762,376422,376082, - 375743,375404,375065,374727,374389,374051,373714,373377, - 373040,372703,372367,372031,371695,371360,371025,370690, - 370356,370022,369688,369355,369021,368688,368356,368023, - 367691,367360,367028,366697,366366,366036,365706,365376, - 365046,364717,364388,364059,363731,363403,363075,362747, - 362420,362093,361766,361440,361114,360788,360463,360137, - 359813,359488,359164,358840,358516,358193,357869,357547, - 357224,356902,356580,356258,355937,355616,355295,354974, - 354654,354334,354014,353695,353376,353057,352739,352420, - 352103,351785,351468,351150,350834,350517,350201,349885, - 349569,349254,348939,348624,348310,347995,347682,347368, - 347055,346741,346429,346116,345804,345492,345180,344869, - 344558,344247,343936,343626,343316,343006,342697,342388, - 342079,341770,341462,341154,340846,340539,340231,339924, - 339618,339311,339005,338700,338394,338089,337784,337479, - 337175,336870,336566,336263,335959,335656,335354,335051, - 334749,334447,334145,333844,333542,333242,332941,332641, - 332341,332041,331741,331442,331143,330844,330546,330247, - 329950,329652,329355,329057,328761,328464,328168,327872, - 327576,327280,326985,326690,326395,326101,325807,325513, - 325219,324926,324633,324340,324047,323755,323463,323171, - 322879,322588,322297,322006,321716,321426,321136,320846, - 320557,320267,319978,319690,319401,319113,318825,318538, - 318250,317963,317676,317390,317103,316817,316532,316246, - 315961,315676,315391,315106,314822,314538,314254,313971, - 313688,313405,313122,312839,312557,312275,311994,311712, - 311431,311150,310869,310589,310309,310029,309749,309470, - 309190,308911,308633,308354,308076,307798,307521,307243, - 306966,306689,306412,306136,305860,305584,305308,305033, - 304758,304483,304208,303934,303659,303385,303112,302838, - 302565,302292,302019,301747,301475,301203,300931,300660, - 300388,300117,299847,299576,299306,299036,298766,298497, - 298227,297958,297689,297421,297153,296884,296617,296349, - 296082,295815,295548,295281,295015,294749,294483,294217, - 293952,293686,293421,293157,292892,292628,292364,292100, - 291837,291574,291311,291048,290785,290523,290261,289999, - 289737,289476,289215,288954,288693,288433,288173,287913, - 287653,287393,287134,286875,286616,286358,286099,285841, - 285583,285326,285068,284811,284554,284298,284041,283785, - 283529,283273,283017,282762,282507,282252,281998,281743, - 281489,281235,280981,280728,280475,280222,279969,279716, - 279464,279212,278960,278708,278457,278206,277955,277704, - 277453,277203,276953,276703,276453,276204,275955,275706, - 275457,275209,274960,274712,274465,274217,273970,273722, - 273476,273229,272982,272736,272490,272244,271999,271753, - 271508,271263,271018,270774,270530,270286,270042,269798, - 269555,269312,269069,268826,268583,268341,268099,267857 -}; - -uint16_t CPTables::old_period_table[OCTAVE*2]={ - - 0x6b00, 0x6800, 0x6500, 0x6220, 0x5f50, 0x5c80, - 0x5a00, 0x5740, 0x54d0, 0x5260, 0x5010, 0x4dc0, - 0x4b90, 0x4960, 0x4750, 0x4540, 0x4350, 0x4160, - 0x3f90, 0x3dc0, 0x3c10, 0x3a40, 0x38b0, 0x3700 -}; - -#define LOGFAC 2*16 - -uint16_t CPTables::log_table[104]= { - LOGFAC*907,LOGFAC*900,LOGFAC*894,LOGFAC*887, - LOGFAC*881,LOGFAC*875,LOGFAC*868,LOGFAC*862, - LOGFAC*856,LOGFAC*850,LOGFAC*844,LOGFAC*838, - LOGFAC*832,LOGFAC*826,LOGFAC*820,LOGFAC*814, - LOGFAC*808,LOGFAC*802,LOGFAC*796,LOGFAC*791, - LOGFAC*785,LOGFAC*779,LOGFAC*774,LOGFAC*768, - LOGFAC*762,LOGFAC*757,LOGFAC*752,LOGFAC*746, - LOGFAC*741,LOGFAC*736,LOGFAC*730,LOGFAC*725, - LOGFAC*720,LOGFAC*715,LOGFAC*709,LOGFAC*704, - LOGFAC*699,LOGFAC*694,LOGFAC*689,LOGFAC*684, - LOGFAC*678,LOGFAC*675,LOGFAC*670,LOGFAC*665, - LOGFAC*660,LOGFAC*655,LOGFAC*651,LOGFAC*646, - LOGFAC*640,LOGFAC*636,LOGFAC*632,LOGFAC*628, - LOGFAC*623,LOGFAC*619,LOGFAC*614,LOGFAC*610, - LOGFAC*604,LOGFAC*601,LOGFAC*597,LOGFAC*592, - LOGFAC*588,LOGFAC*584,LOGFAC*580,LOGFAC*575, - LOGFAC*570,LOGFAC*567,LOGFAC*563,LOGFAC*559, - LOGFAC*555,LOGFAC*551,LOGFAC*547,LOGFAC*543, - LOGFAC*538,LOGFAC*535,LOGFAC*532,LOGFAC*528, - LOGFAC*524,LOGFAC*520,LOGFAC*516,LOGFAC*513, - LOGFAC*508,LOGFAC*505,LOGFAC*502,LOGFAC*498, - LOGFAC*494,LOGFAC*491,LOGFAC*487,LOGFAC*484, - LOGFAC*480,LOGFAC*477,LOGFAC*474,LOGFAC*470, - LOGFAC*467,LOGFAC*463,LOGFAC*460,LOGFAC*457, - LOGFAC*453,LOGFAC*450,LOGFAC*447,LOGFAC*443, - LOGFAC*440,LOGFAC*437,LOGFAC*434,LOGFAC*431 -}; - - - -int32_t CPTables::get_linear_period(uint16_t note,int32_t fine) { - - int32_t t; - - t=(24L*OCTAVE-(int32_t)note)*32L-(fine>>1); - return t; -} - -static int s3m_period_table[12]={1712,1616,1524,1440,1356,1280,1208,1140,1076,1016,960,907}; - - -int32_t CPTables::get_log_period(uint16_t note,int32_t p_c5freq) { - - return (8363L * 16 * s3m_period_table[note%12] >> (note/12)) / p_c5freq; - -} - -/* -int32_t CPTables::get_log_period(uint16_t note,int32_t p_c5freq) -{ - uint16_t n,o; - uint16_t p1,p2; - int32_t i; - - n=note%(2*OCTAVE); - o=note/(2*OCTAVE); - i=(n<<2); // n*8 + fine/16 - - if (i<0) - i=0; - - if (i>102) - i=102; - - - p1=log_table[i]; - p2=log_table[i+1]; - - - return (Interpolate(fine>>4,0,15,p1,p2)>>o); - -} */ - -int32_t CPTables::get_old_period(uint16_t note,int32_t speed) { - - uint16_t n,o,res; - -// if (!speed) { - - // return 4242; /* <- prevent divide overflow */ - // } - - n=note%(2*OCTAVE); - o=note/(2*OCTAVE); - - res=((8363L*(int32_t)old_period_table[n])>>o)/((old_period_table[17]>>1)+(speed<<2)); /*/(128-speed)*/; - - return res; -} - -int32_t CPTables::get_linear_frequency(int32_t period) { - - int32_t shift_value=(((int32_t)period/768)-2); - if (shift_value>0) { - - return linear_period_to_freq_tab[period%768]>>shift_value; - } else { - shift_value=0-shift_value; - return linear_period_to_freq_tab[period%768]<<shift_value; - } -} - -int32_t CPTables::get_old_frequency(int32_t period) { - - return (8363L*1712L)/(period?period:1); - -} - -CPTables::CPTables(){ -} -CPTables::~CPTables(){ -} diff --git a/modules/chibi/cp_tables.h b/modules/chibi/cp_tables.h deleted file mode 100644 index 4baa1c648..000000000 --- a/modules/chibi/cp_tables.h +++ /dev/null @@ -1,67 +0,0 @@ -/*************************************************************************/ -/* cp_tables.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef CPTABLES_H -#define CPTABLES_H - -#include "cp_config.h" - -/**conversion CPTables/functions - *@author Juan Linietsky - */ - -/****************************** - CPTables.h - -------- - -CPTables methods for miscelaneous -conversion utilities -********************************/ - -class CPTables { -public: - - enum { OCTAVE=12 }; - - static uint16_t old_period_table[OCTAVE*2]; - static uint16_t log_table[104]; - static int32_t linear_period_to_freq_tab[768]; - - static int32_t get_old_period(uint16_t note,int32_t speed); - static int32_t get_amiga_period(uint16_t note,int32_t fine); - static int32_t get_linear_period(uint16_t note,int32_t fine); - static int32_t get_linear_frequency(int32_t period); - static int32_t get_old_frequency(int32_t period); - static int32_t get_log_period(uint16_t note,int32_t p_c5freq); - - CPTables(); - ~CPTables(); -}; - -#endif diff --git a/modules/chibi/event_stream_chibi.cpp b/modules/chibi/event_stream_chibi.cpp deleted file mode 100644 index 73d1c01e3..000000000 --- a/modules/chibi/event_stream_chibi.cpp +++ /dev/null @@ -1,872 +0,0 @@ -/*************************************************************************/ -/* event_stream_chibi.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "event_stream_chibi.h" -#include "cp_loader_it.h" -#include "cp_loader_xm.h" -#include "cp_loader_s3m.h" -#include "cp_loader_mod.h" - -static CPSampleManagerImpl *sample_manager; -static ResourceFormatLoaderChibi *resource_loader; - -CPSample_ID CPSampleManagerImpl::create(bool p_16bits,bool p_stereo,int32_t p_len) { - - AudioServer::SampleFormat sf=p_16bits?AudioServer::SAMPLE_FORMAT_PCM16:AudioServer::SAMPLE_FORMAT_PCM8; - - SampleData *sd = memnew( SampleData ); - sd->rid = AudioServer::get_singleton()->sample_create(sf,p_stereo,p_len); - sd->stereo=p_stereo; - sd->len=p_len; - sd->is16=p_16bits; - sd->mixfreq=44100; - sd->loop_begin=0; - sd->loop_end=0; - sd->loop_type=CP_LOOP_NONE; - sd->locks=0; -#ifdef DEBUG_ENABLED - valid.insert(sd); -#endif - CPSample_ID sid; - sid._private=sd; - return sid; -} - -void CPSampleManagerImpl::recreate(CPSample_ID p_id,bool p_16bits,bool p_stereo,int32_t p_len){ - - AudioServer::SampleFormat sf=p_16bits?AudioServer::SAMPLE_FORMAT_PCM16:AudioServer::SAMPLE_FORMAT_PCM8; - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND(!valid.has(sd)); -#endif - AudioServer::get_singleton()->free(sd->rid); - sd->rid = AudioServer::get_singleton()->sample_create(sf,p_stereo,p_len); - sd->stereo=p_stereo; - sd->len=p_len; - sd->is16=p_16bits; - sd->mixfreq=44100; - sd->loop_begin=0; - sd->loop_end=0; - sd->loop_type=CP_LOOP_NONE; -} -void CPSampleManagerImpl::destroy(CPSample_ID p_id){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND(!valid.has(sd)); - valid.erase(sd); -#endif - AudioServer::get_singleton()->free(sd->rid); - - memdelete(sd); -} -bool CPSampleManagerImpl::check(CPSample_ID p_id){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - return valid.has(sd); -#else - return _getsd(p_id)!=NULL; -#endif -} - -void CPSampleManagerImpl::set_c5_freq(CPSample_ID p_id,int32_t p_freq){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND(!valid.has(sd)); -#endif - sd->mixfreq=p_freq; - AudioServer::get_singleton()->sample_set_mix_rate(sd->rid,p_freq); - -} -void CPSampleManagerImpl::set_loop_begin(CPSample_ID p_id,int32_t p_begin){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND(!valid.has(sd)); -#endif - sd->loop_begin=p_begin; - AudioServer::get_singleton()->sample_set_loop_begin(sd->rid,p_begin); - -} -void CPSampleManagerImpl::set_loop_end(CPSample_ID p_id,int32_t p_end){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND(!valid.has(sd)); -#endif - sd->loop_end=p_end; - AudioServer::get_singleton()->sample_set_loop_end(sd->rid,p_end); - -} -void CPSampleManagerImpl::set_loop_type(CPSample_ID p_id,CPSample_Loop_Type p_type){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND(!valid.has(sd)); -#endif - - sd->loop_type=p_type; - AudioServer::get_singleton()->sample_set_loop_format(sd->rid,AudioServer::SampleLoopFormat(p_type)); - - -} -void CPSampleManagerImpl::set_chunk(CPSample_ID p_id,int32_t p_index,void *p_data,int p_data_len){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND(!valid.has(sd)); -#endif - - ERR_FAIL(); -} - - -int32_t CPSampleManagerImpl::get_loop_begin(CPSample_ID p_id){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND_V(!valid.has(sd),0); -#endif - - return sd->loop_begin; - -} -int32_t CPSampleManagerImpl::get_loop_end(CPSample_ID p_id){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND_V(!valid.has(sd),0); -#endif - - return sd->loop_end; -} -CPSample_Loop_Type CPSampleManagerImpl::get_loop_type(CPSample_ID p_id){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND_V(!valid.has(sd),CP_LOOP_NONE); -#endif - - return sd->loop_type; -} -int32_t CPSampleManagerImpl::get_c5_freq(CPSample_ID p_id){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND_V(!valid.has(sd),0); -#endif - - return sd->mixfreq; -} -int32_t CPSampleManagerImpl::get_size(CPSample_ID p_id){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND_V(!valid.has(sd),0); -#endif - - return sd->len; - -} -bool CPSampleManagerImpl::is_16bits(CPSample_ID p_id){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND_V(!valid.has(sd),false); -#endif - - return sd->is16; - -} -bool CPSampleManagerImpl::is_stereo(CPSample_ID p_id){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND_V(!valid.has(sd),false); -#endif - return sd->stereo; - - -} -bool CPSampleManagerImpl::lock_data(CPSample_ID p_id){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND_V(!valid.has(sd),0); -#endif - - sd->locks++; - if (sd->locks==1) { - sd->lock=AudioServer::get_singleton()->sample_get_data(sd->rid); - sd->w=sd->lock.write(); - } - - return true; -} -void *CPSampleManagerImpl::get_data(CPSample_ID p_id){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND_V(!valid.has(sd),0); -#endif - - ERR_FAIL_COND_V(sd->locks==0,0); - return sd->w.ptr(); -} - -int16_t CPSampleManagerImpl::get_data(CPSample_ID p_id, int p_sample, int p_channel){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND_V(!valid.has(sd),0); -#endif - - ERR_FAIL_V(0); - lock_data(p_id); - - int sofs = sd->stereo ? 2:1; - uint16_t v=0; - if (sd->is16) { - int16_t *p=(int16_t*)sd->w.ptr(); - v=p[p_sample*sofs+p_channel]; - } else { - int8_t *p=(int8_t*)sd->w.ptr(); - v=p[p_sample*sofs+p_channel]; - } - - unlock_data(p_id); - - return v; -} -void CPSampleManagerImpl::set_data(CPSample_ID p_id, int p_sample, int16_t p_data,int p_channel){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND(!valid.has(sd)); -#endif - - ERR_FAIL(); - lock_data(p_id); - - int sofs = sd->stereo ? 2:1; - if (sd->is16) { - int16_t *p=(int16_t*)sd->w.ptr(); - p[p_sample*sofs+p_channel]=p_data; - } else { - int8_t *p=(int8_t*)sd->w.ptr(); - p[p_sample*sofs+p_channel]=p_data; - } - - unlock_data(p_id); - -} -void CPSampleManagerImpl::unlock_data(CPSample_ID p_id){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND(!valid.has(sd)); -#endif - - ERR_FAIL_COND(sd->locks==0); - - sd->locks--; - if (sd->locks==0) { - sd->w=PoolVector<uint8_t>::Write(); - AudioServer::get_singleton()->sample_set_data(sd->rid,sd->lock); - sd->lock=PoolVector<uint8_t>(); - } -} - -void CPSampleManagerImpl::get_chunk(CPSample_ID p_id,int32_t p_index,void *p_data,int p_data_len) { - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND(!valid.has(sd)); -#endif - - ERR_FAIL(); -} - - -/** MIXER **/ - -void CPMixerImpl::set_callback_interval(int p_interval_us) { - - callback_interval=p_interval_us; -} - -void CPMixerImpl::set_callback(void (*p_callback)(void*),void *p_userdata) { - - callback=p_callback; - userdata=p_userdata; -} - -void CPMixerImpl::setup_voice(int p_voice_index,CPSample_ID p_sample_id,int32_t p_start_index) { - - Voice &v=voices[p_voice_index]; - if (v.channel!=AudioMixer::INVALID_CHANNEL) { - mixer->channel_free(v.channel); - } - v.channel=mixer->channel_alloc(sample_manager->get_rid(p_sample_id)); - v.freq_mult = sample_manager->get_c5_freq(p_sample_id)/261.6255653006; - v.sample = p_sample_id; -} - -void CPMixerImpl::stop_voice(int p_voice_index) { - - Voice &v=voices[p_voice_index]; - if (v.channel==AudioMixer::INVALID_CHANNEL) - return; - - mixer->channel_free(v.channel); - v.channel=AudioMixer::INVALID_CHANNEL; - -} - -void CPMixerImpl::set_voice_frequency(int p_voice_index,int32_t p_freq) { - - Voice &v=voices[p_voice_index]; - ERR_FAIL_COND(v.channel==AudioMixer::INVALID_CHANNEL); - float f = p_freq / 256.0; - f*=pitch_scale; - mixer->channel_set_mix_rate(v.channel,f * v.freq_mult ); -} - -void CPMixerImpl::set_voice_panning(int p_voice_index,int p_pan) { - - Voice &v=voices[p_voice_index]; - ERR_FAIL_COND(v.channel==AudioMixer::INVALID_CHANNEL); - if (p_pan==CP_PAN_SURROUND) - p_pan=CP_PAN_CENTER; - float p = p_pan / 256.0; - mixer->channel_set_pan(v.channel,p); - -} - -void CPMixerImpl::set_voice_volume(int p_voice_index,int p_vol) { - - - Voice &v=voices[p_voice_index]; - ERR_FAIL_COND(v.channel==AudioMixer::INVALID_CHANNEL); - float vol = p_vol/512.0; - vol*=voice_scale; - mixer->channel_set_volume(v.channel,vol); - mixer->channel_set_reverb(v.channel,reverb_type,vol*v.reverb); -} - -void CPMixerImpl::set_voice_filter(int p_voice_index,bool p_enabled,uint8_t p_cutoff, uint8_t p_resonance ){ - - Voice &v=voices[p_voice_index]; - ERR_FAIL_COND(v.channel==AudioMixer::INVALID_CHANNEL); - -} - -void CPMixerImpl::set_voice_reverb_send(int p_voice_index,int p_reverb){ - - Voice &v=voices[p_voice_index]; - ERR_FAIL_COND(v.channel==AudioMixer::INVALID_CHANNEL); - v.reverb=p_reverb/255.0; - //mixer->channel_set_reverb(v.channel,reverb_type,p_reverb/255.0); - -} - -void CPMixerImpl::set_voice_chorus_send(int p_voice_index,int p_chorus){ - - Voice &v=voices[p_voice_index]; - ERR_FAIL_COND(v.channel==AudioMixer::INVALID_CHANNEL); - mixer->channel_set_chorus(v.channel,p_chorus/255.0); - -} - - -void CPMixerImpl::set_reverb_mode(ReverbMode p_mode){ - -// Voice &v=voices[p_voice_index]; -// ERR_FAIL_COND(v.channel==AudioMixer::INVALID_CHANNEL); - switch(p_mode) { - case CPMixer::REVERB_MODE_STUDIO_SMALL: reverb_type=AudioMixer::REVERB_SMALL; break; - case CPMixer::REVERB_MODE_STUDIO_MEDIUM: reverb_type=AudioMixer::REVERB_MEDIUM; break; - case CPMixer::REVERB_MODE_STUDIO_LARGE: reverb_type=AudioMixer::REVERB_LARGE; break; - case CPMixer::REVERB_MODE_HALL: reverb_type=AudioMixer::REVERB_HALL; break; - default: reverb_type=AudioMixer::REVERB_SMALL; break; - } - -} - -void CPMixerImpl::set_chorus_params(unsigned int p_delay_ms,unsigned int p_separation_ms,unsigned int p_depth_ms10,unsigned int p_speed_hz10){ - -// Voice &v=voices[p_voice_index]; -// ERR_FAIL_COND(v.channel==AudioMixer::INVALID_CHANNEL); - -} - - - -/* Info retrieving */ - -int32_t CPMixerImpl::get_voice_sample_pos_index(int p_voice_index) { - - Voice &v=voices[p_voice_index]; - ERR_FAIL_COND_V(v.channel==AudioMixer::INVALID_CHANNEL,0); - return 0; - -} - -int CPMixerImpl::get_voice_panning(int p_voice_index) { - - Voice &v=voices[p_voice_index]; - ERR_FAIL_COND_V(!is_voice_active(p_voice_index),0); - return mixer->channel_get_pan(v.channel)*CP_PAN_RIGHT; - -} - -int CPMixerImpl::get_voice_volume(int p_voice_index) { - - Voice &v=voices[p_voice_index]; - ERR_FAIL_COND_V(!is_voice_active(p_voice_index),0); - return mixer->channel_get_volume(v.channel); - - -} - -CPSample_ID CPMixerImpl::get_voice_sample_id(int p_voice_index) { - - Voice &v=voices[p_voice_index]; - ERR_FAIL_COND_V(v.channel==AudioMixer::INVALID_CHANNEL,CPSample_ID()); - return v.sample; - - -} - -bool CPMixerImpl::is_voice_active(int p_voice_index){ - - Voice &v=voices[p_voice_index]; - if (v.channel==AudioMixer::INVALID_CHANNEL) - return false; - if (!mixer->channel_is_valid(v.channel)) - v.channel=AudioMixer::INVALID_CHANNEL; - - return v.channel!=AudioMixer::INVALID_CHANNEL; -} - -void CPMixerImpl::process_usecs(int p_usec,float p_volume,float p_pitch_scale,float p_tempo_scale) { - - ERR_FAIL_COND(callback_interval==0); - //update this somewhere - pitch_scale=p_pitch_scale; - tempo_scale=p_tempo_scale; - voice_scale = AudioServer::get_singleton()->get_event_voice_global_volume_scale()*p_volume; - while(p_usec) { - - if (p_usec>=callback_timeout) { - - p_usec-=callback_timeout; - callback_timeout=0; - if (callback) { - callback(userdata); - } - callback_timeout=callback_interval*(1.0/p_tempo_scale); - - } else { - - callback_timeout-=p_usec; - p_usec=0; - } - } -} - - -CPMixerImpl::CPMixerImpl(AudioMixer *p_mixer) { - - callback_interval=1; - callback_timeout=0; - userdata=0; - callback=0; - tempo_scale=1.0; - pitch_scale=1.0; - mixer=p_mixer; - voice_scale = AudioServer::get_singleton()->get_event_voice_global_volume_scale(); - reverb_type = AudioMixer::REVERB_SMALL; - -} - -/** FILE ACCESS WRAPPER **/ - - -CPFileAccessWrapperImpl::Error CPFileAccessWrapperImpl::open(const char *p_filename, int p_mode_flags) { - - ERR_FAIL_COND_V(p_mode_flags&WRITE,ERROR_WRITING_FILE); - close(); - f = FileAccess::open(String::utf8(p_filename),p_mode_flags); - if (!f) - return ERROR_FILE_NOT_FOUND; - return OK; -} - -void CPFileAccessWrapperImpl::close(){ - - if (f) - memdelete(f); - f=NULL; - - -} - -void CPFileAccessWrapperImpl::seek(uint32_t p_position){ - - f->seek(p_position); -} -void CPFileAccessWrapperImpl::seek_end(){ - - f->seek_end(); -} -uint32_t CPFileAccessWrapperImpl::get_pos(){ - - return f->get_pos(); -} - -bool CPFileAccessWrapperImpl::eof_reached(){ - - return f->eof_reached(); -} - -uint8_t CPFileAccessWrapperImpl::get_byte(){ - - return f->get_8(); -} -void CPFileAccessWrapperImpl::get_byte_array(uint8_t *p_dest,int p_elements){ - - f->get_buffer(p_dest,p_elements); -} -void CPFileAccessWrapperImpl::get_word_array(uint16_t *p_dest,int p_elements){ - - for(int i=0;i<p_elements;i++) { - p_dest[i]=f->get_16(); - } - -} - -uint16_t CPFileAccessWrapperImpl::get_word(){ - - return f->get_16(); -} -uint32_t CPFileAccessWrapperImpl::get_dword(){ - - return f->get_32(); -} - -void CPFileAccessWrapperImpl::set_endian_conversion(bool p_swap){ - - f->set_endian_swap(p_swap); -} -bool CPFileAccessWrapperImpl::is_open(){ - - return f!=NULL; -} - -CPFileAccessWrapperImpl::Error CPFileAccessWrapperImpl::get_error(){ - - return (f->get_error()!=::OK)?ERROR_READING_FILE:OK; -} - -void CPFileAccessWrapperImpl::store_byte(uint8_t p_dest){ - -} -void CPFileAccessWrapperImpl::store_byte_array(const uint8_t *p_dest,int p_elements){ - -} - -void CPFileAccessWrapperImpl::store_word(uint16_t p_dest){ - -} -void CPFileAccessWrapperImpl::store_dword(uint32_t p_dest){ - -} - -//////////////////////////////////////////////// - - -Error EventStreamPlaybackChibi::_play() { - - last_order=0; - loops=0; - player->play_start_song(); - total_usec=0; - - return OK; -} - -bool EventStreamPlaybackChibi::_update(AudioMixer* p_mixer, uint64_t p_usec){ - - total_usec+=p_usec; - mixer.process_usecs(p_usec,volume,pitch_scale,tempo_scale); - int order=player->get_current_order(); - if (order<last_order) { - if (!loop) { - stop(); - } else { - loops++; - } - } - last_order=order; - return false; -} -void EventStreamPlaybackChibi::_stop(){ - - player->play_stop(); -} - -void EventStreamPlaybackChibi::set_paused(bool p_paused){ - -} -bool EventStreamPlaybackChibi::is_paused() const{ - - return false; -} -void EventStreamPlaybackChibi::set_loop(bool p_loop){ - - loop=p_loop; - -} -bool EventStreamPlaybackChibi::is_loop_enabled() const{ - - return loop; -} - -int EventStreamPlaybackChibi::get_loop_count() const{ - - //return player->is - return loops; -} - -float EventStreamPlaybackChibi::get_pos() const{ - - return double(total_usec)/1000000.0; -} -void EventStreamPlaybackChibi::seek_pos(float p_time){ - - WARN_PRINT("seek_pos unimplemented."); -} - -void EventStreamPlaybackChibi::set_volume(float p_volume) { - - volume=p_volume; -} - -float EventStreamPlaybackChibi::get_volume() const{ - - return volume; -} - -void EventStreamPlaybackChibi::set_pitch_scale(float p_pitch_scale) { - - pitch_scale=p_pitch_scale; -} - -float EventStreamPlaybackChibi::get_pitch_scale() const{ - - return pitch_scale; -} - -void EventStreamPlaybackChibi::set_tempo_scale(float p_tempo_scale) { - - tempo_scale=p_tempo_scale; -} - -float EventStreamPlaybackChibi::get_tempo_scale() const{ - - return tempo_scale; -} - - -void EventStreamPlaybackChibi::set_channel_volume(int p_channel,float p_volume) { - - - if (p_channel>=64) - return; - player->set_channel_global_volume(p_channel,p_volume*256); -} - - - -float EventStreamPlaybackChibi::get_channel_volume(int p_channel) const{ - - return player->get_channel_global_volume(p_channel)/256.0; - -} - -float EventStreamPlaybackChibi::get_last_note_time(int p_channel) const { - - - double v = (player->get_channel_last_note_time_usec(p_channel))/1000000.0; - if (v<0) - v=-1; - return v; -} - -EventStreamPlaybackChibi::EventStreamPlaybackChibi(Ref<EventStreamChibi> p_stream) : mixer(_get_mixer()) { - - stream=p_stream; - player = memnew( CPPlayer(&mixer,&p_stream->song) ); - loop=false; - last_order=0; - loops=0; - volume=1.0; - pitch_scale=1.0; - tempo_scale=1.0; -} -EventStreamPlaybackChibi::~EventStreamPlaybackChibi(){ - - player->play_stop(); - memdelete(player); -} - -//////////////////////////////////////////////////// - -Ref<EventStreamPlayback> EventStreamChibi::instance_playback() { - - return Ref<EventStreamPlayback>( memnew(EventStreamPlaybackChibi(Ref<EventStreamChibi>(this))) ); -} - -String EventStreamChibi::get_stream_name() const{ - - return song.get_name(); - -} - - - -float EventStreamChibi::get_length() const{ - - return 1; -} - - -EventStreamChibi::EventStreamChibi() { - - -} - - - -////////////////////////////////////////////////////////////////// - - - - -RES ResourceFormatLoaderChibi::load(const String &p_path, const String& p_original_path, Error *r_error) { - - if (r_error) - *r_error=ERR_FILE_CANT_OPEN; - String el = p_path.extension().to_lower(); - - CPFileAccessWrapperImpl f; - - if (el=="it") { - - Ref<EventStreamChibi> esc( memnew( EventStreamChibi ) ); - CPLoader_IT loader(&f); - CPLoader::Error err = loader.load_song(p_path.utf8().get_data(),&esc->song,false); - ERR_FAIL_COND_V(err!=CPLoader::FILE_OK,RES()); - if (r_error) - *r_error=OK; - - return esc; - - } else if (el=="xm") { - - Ref<EventStreamChibi> esc( memnew( EventStreamChibi ) ); - CPLoader_XM loader(&f); - CPLoader::Error err=loader.load_song(p_path.utf8().get_data(),&esc->song,false); - ERR_FAIL_COND_V(err!=CPLoader::FILE_OK,RES()); - if (r_error) - *r_error=OK; - return esc; - - } else if (el=="s3m") { - - Ref<EventStreamChibi> esc( memnew( EventStreamChibi ) ); - CPLoader_S3M loader(&f); - CPLoader::Error err=loader.load_song(p_path.utf8().get_data(),&esc->song,false); - ERR_FAIL_COND_V(err!=CPLoader::FILE_OK,RES()); - if (r_error) - *r_error=OK; - - return esc; - - } else if (el=="mod") { - - Ref<EventStreamChibi> esc( memnew( EventStreamChibi ) ); - CPLoader_MOD loader(&f); - CPLoader::Error err=loader.load_song(p_path.utf8().get_data(),&esc->song,false); - ERR_FAIL_COND_V(err!=CPLoader::FILE_OK,RES()); - if (r_error) - *r_error=OK; - return esc; - } - - return RES(); - -} - -void ResourceFormatLoaderChibi::get_recognized_extensions(List<String> *p_extensions) const { - - p_extensions->push_back("it"); - p_extensions->push_back("xm"); - p_extensions->push_back("s3m"); - p_extensions->push_back("mod"); -} -bool ResourceFormatLoaderChibi::handles_type(const String& p_type) const { - - return (p_type=="EventStreamChibi" || p_type=="EventStream"); -} - -String ResourceFormatLoaderChibi::get_resource_type(const String &p_path) const { - String el = p_path.extension().to_lower(); - if (el=="it" || el=="s3m" || el=="xm" || el=="mod") - return "EventStreamChibi"; - return ""; -} - -///////////////////////////////////////////////////////////////// -void initialize_chibi() { - - sample_manager = memnew( CPSampleManagerImpl ); - resource_loader = memnew( ResourceFormatLoaderChibi ); - ClassDB::register_class<EventStreamChibi>(); - ResourceLoader::add_resource_format_loader( resource_loader ); -} - -void finalize_chibi() { - - memdelete( sample_manager ); - memdelete( resource_loader ); -} - diff --git a/modules/chibi/event_stream_chibi.h b/modules/chibi/event_stream_chibi.h deleted file mode 100644 index 0244ee0a9..000000000 --- a/modules/chibi/event_stream_chibi.h +++ /dev/null @@ -1,314 +0,0 @@ -/*************************************************************************/ -/* event_stream_chibi.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef EVENT_STREAM_CHIBI_H -#define EVENT_STREAM_CHIBI_H - -#include "scene/resources/event_stream.h" -#include "cp_sample_manager.h" -#include "cp_mixer.h" -#include "cp_song.h" -#include "cp_file_access_wrapper.h" -#include "cp_player_data.h" -#include "resource.h" -#include "servers/audio_server.h" -#include "os/file_access.h" -#include "io/resource_loader.h" - -/** SAMPLE MANAGER **/ - -class CPSampleManagerImpl : public CPSampleManager { - - struct SampleData { - - RID rid; - bool stereo; - bool is16; - int len; - int mixfreq; - int loop_begin; - int loop_end; - int locks; - PoolVector<uint8_t> lock; - PoolVector<uint8_t>::Write w; - CPSample_Loop_Type loop_type; - }; - - - _FORCE_INLINE_ SampleData* _getsd(CPSample_ID p_id) { - - return ((SampleData*)p_id._private); - } - Set<SampleData*> valid; - -public: - - _FORCE_INLINE_ RID get_rid(CPSample_ID p_id) { return _getsd(p_id)->rid; } - virtual CPSample_ID create(bool p_16bits,bool p_stereo,int32_t p_len); - virtual void recreate(CPSample_ID p_id,bool p_16bits,bool p_stereo,int32_t p_len); - virtual void destroy(CPSample_ID p_id); - virtual bool check(CPSample_ID p_id); // return false if invalid - - virtual void set_c5_freq(CPSample_ID p_id,int32_t p_freq); - virtual void set_loop_begin(CPSample_ID p_id,int32_t p_begin); - virtual void set_loop_end(CPSample_ID p_id,int32_t p_end); - virtual void set_loop_type(CPSample_ID p_id,CPSample_Loop_Type p_type); - virtual void set_chunk(CPSample_ID p_id,int32_t p_index,void *p_data,int p_data_len); - - - virtual int32_t get_loop_begin(CPSample_ID p_id); - virtual int32_t get_loop_end(CPSample_ID p_id); - virtual CPSample_Loop_Type get_loop_type(CPSample_ID p_id); - virtual int32_t get_c5_freq(CPSample_ID p_id); - virtual int32_t get_size(CPSample_ID p_id); - virtual bool is_16bits(CPSample_ID p_id); - virtual bool is_stereo(CPSample_ID p_id); - virtual bool lock_data(CPSample_ID p_id); - virtual void *get_data(CPSample_ID p_id); /* WARNING: Not all sample managers -may be able to implement this, it depends on the mixer in use! */ - virtual int16_t get_data(CPSample_ID p_id, int p_sample, int p_channel=0); /// Does not need locking - virtual void set_data(CPSample_ID p_id, int p_sample, int16_t p_data,int p_channel=0); /// Does not need locking - virtual void unlock_data(CPSample_ID p_id); - - virtual void get_chunk(CPSample_ID p_id,int32_t p_index,void *p_data,int p_data_len); - -}; - - -/** MIXER **/ - -class CPMixerImpl : public CPMixer { - - enum { - MAX_VOICES=64 - }; - - struct Voice { - - AudioMixer::ChannelID channel; - CPSample_ID sample; - float freq_mult; - float reverb; - Voice() { reverb=0.0; } - }; - - Voice voices[MAX_VOICES]; - - - int callback_interval; - int callback_timeout; - void (*callback)(void*); - void *userdata; - float voice_scale; - float tempo_scale; - float pitch_scale; - AudioMixer::ReverbRoomType reverb_type; - AudioMixer *mixer; -public: - - void process_usecs(int p_usec,float p_volume,float p_pitch_scale,float p_tempo_scale); - - /* Callback */ - - virtual void set_callback_interval(int p_interval_us); //in usecs, for tracker it's 2500000/tempo - virtual void set_callback(void (*p_callback)(void*),void *p_userdata); - - /* Voice Control */ - - virtual void setup_voice(int p_voice_index,CPSample_ID p_sample_id,int32_t p_start_index) ; - virtual void stop_voice(int p_voice_index) ; - virtual void set_voice_frequency(int p_voice_index,int32_t p_freq) ; //in freq*FREQUENCY_BITS - virtual void set_voice_panning(int p_voice_index,int p_pan) ; - virtual void set_voice_volume(int p_voice_index,int p_vol) ; - virtual void set_voice_filter(int p_filter,bool p_enabled,uint8_t p_cutoff, uint8_t p_resonance ); - virtual void set_voice_reverb_send(int p_voice_index,int p_reverb); - virtual void set_voice_chorus_send(int p_voice_index,int p_chorus); /* 0 - 255 */ - - virtual void set_reverb_mode(ReverbMode p_mode); - virtual void set_chorus_params(unsigned int p_delay_ms,unsigned int p_separation_ms,unsigned int p_depth_ms10,unsigned int p_speed_hz10); - - - /* Info retrieving */ - - virtual int32_t get_voice_sample_pos_index(int p_voice_index) ; - virtual int get_voice_panning(int p_voice_index) ; - virtual int get_voice_volume(int p_voice_index) ; - virtual CPSample_ID get_voice_sample_id(int p_voice_index) ; - virtual bool is_voice_active(int p_voice_index); - virtual int get_active_voice_count() { return 0; } - virtual int get_total_voice_count() { return MAX_VOICES; } - - - virtual uint32_t get_mix_frequency() { return 0; } - - /* Methods below only work with software mixers, meant for software-based sound drivers, hardware mixers ignore them */ - virtual int32_t process(int32_t p_frames) { return 0; } - virtual int32_t *get_mixdown_buffer_ptr() { return NULL; } - virtual void set_mix_frequency(int32_t p_mix_frequency) {}; - - CPMixerImpl(AudioMixer *p_mixer=NULL); - virtual ~CPMixerImpl() {} -}; - -/** FILE ACCESS **/ - -class CPFileAccessWrapperImpl : public CPFileAccessWrapper { - - FileAccess *f; -public: - - - virtual Error open(const char *p_filename, int p_mode_flags); - virtual void close(); - - virtual void seek(uint32_t p_position); - virtual void seek_end(); - virtual uint32_t get_pos(); - - virtual bool eof_reached(); - - virtual uint8_t get_byte(); - virtual void get_byte_array(uint8_t *p_dest,int p_elements); - virtual void get_word_array(uint16_t *p_dest,int p_elements); - - virtual uint16_t get_word(); - virtual uint32_t get_dword(); - - virtual void set_endian_conversion(bool p_swap); - virtual bool is_open(); - - virtual Error get_error(); - - virtual void store_byte(uint8_t p_dest); - virtual void store_byte_array(const uint8_t *p_dest,int p_elements); - - virtual void store_word(uint16_t p_dest); - virtual void store_dword(uint32_t p_dest); - - CPFileAccessWrapperImpl() { f=NULL; } - virtual ~CPFileAccessWrapperImpl(){ if (f) memdelete(f); } - -}; - - - -///////////////////// - -class EventStreamChibi; - -class EventStreamPlaybackChibi : public EventStreamPlayback { - - GDCLASS(EventStreamPlaybackChibi,EventStreamPlayback); - - CPMixerImpl mixer; - uint64_t total_usec; - Ref<EventStreamChibi> stream; - mutable CPPlayer *player; - bool loop; - int last_order; - int loops; - virtual Error _play(); - virtual bool _update(AudioMixer* p_mixer, uint64_t p_usec); - virtual void _stop(); - float volume; - float tempo_scale; - float pitch_scale; - - -public: - - - virtual void set_paused(bool p_paused); - virtual bool is_paused() const; - - virtual void set_loop(bool p_loop); - virtual bool is_loop_enabled() const; - - virtual int get_loop_count() const; - - virtual float get_pos() const; - virtual void seek_pos(float p_time); - - virtual void set_volume(float p_vol); - virtual float get_volume() const; - - virtual void set_pitch_scale(float p_pitch_scale); - virtual float get_pitch_scale() const; - - virtual void set_tempo_scale(float p_tempo_scale); - virtual float get_tempo_scale() const; - - virtual void set_channel_volume(int p_channel,float p_volume); - virtual float get_channel_volume(int p_channel) const; - - virtual float get_last_note_time(int p_channel) const; - - EventStreamPlaybackChibi(Ref<EventStreamChibi> p_stream=Ref<EventStreamChibi>()); - ~EventStreamPlaybackChibi(); -}; - - -class EventStreamChibi : public EventStream { - - GDCLASS(EventStreamChibi,EventStream); - -friend class ResourceFormatLoaderChibi; -friend class EventStreamPlaybackChibi; - //I think i didn't know what const was when i wrote this more than a decade ago - //so it goes mutable :( - mutable CPSong song; - - -public: - - virtual Ref<EventStreamPlayback> instance_playback(); - - virtual String get_stream_name() const; - - virtual float get_length() const; - - virtual int get_channel_count() const { return 64; } //tracker limit - - EventStreamChibi(); -}; - - -class ResourceFormatLoaderChibi : public ResourceFormatLoader { - -public: - virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL); - virtual void get_recognized_extensions(List<String> *p_extensions) const; - virtual bool handles_type(const String& p_type) const; - virtual String get_resource_type(const String &p_path) const; - -}; - -void initialize_chibi(); -void finalize_chibi(); - -#endif // EVENT_STREAM_CHIBI_H diff --git a/modules/dds/texture_loader_dds.cpp b/modules/dds/texture_loader_dds.cpp index 1de98a6b1..600cae991 100644 --- a/modules/dds/texture_loader_dds.cpp +++ b/modules/dds/texture_loader_dds.cpp @@ -114,7 +114,7 @@ RES ResourceFormatDDS::load(const String &p_path, const String& p_original_path, uint32_t width = f->get_32(); uint32_t height = f->get_32(); uint32_t pitch = f->get_32(); - uint32_t depth = f->get_32(); + /* uint32_t depth = */ f->get_32(); uint32_t mipmaps = f->get_32(); //skip 11 @@ -130,7 +130,7 @@ RES ResourceFormatDDS::load(const String &p_path, const String& p_original_path, } - uint32_t format_size = f->get_32(); + /* uint32_t format_size = */ f->get_32(); uint32_t format_flags = f->get_32(); uint32_t format_fourcc = f->get_32(); uint32_t format_rgb_bits = f->get_32(); @@ -139,9 +139,9 @@ RES ResourceFormatDDS::load(const String &p_path, const String& p_original_path, uint32_t format_blue_mask = f->get_32(); uint32_t format_alpha_mask = f->get_32(); - uint32_t caps_1 = f->get_32(); - uint32_t caps_2 = f->get_32(); - uint32_t caps_ddsx = f->get_32(); + /* uint32_t caps_1 = */ f->get_32(); + /* uint32_t caps_2 = */ f->get_32(); + /* uint32_t caps_ddsx = */ f->get_32(); //reserved skip f->get_32(); @@ -221,7 +221,7 @@ RES ResourceFormatDDS::load(const String &p_path, const String& p_original_path, if (!(flags&DDSD_MIPMAPCOUNT)) mipmaps=1; -// print_line("found format: "+String(dds_format_info[dds_format].name)); + //print_line("found format: "+String(dds_format_info[dds_format].name)); PoolVector<uint8_t> src_data; @@ -478,7 +478,7 @@ bool ResourceFormatDDS::handles_type(const String& p_type) const { String ResourceFormatDDS::get_resource_type(const String &p_path) const { - if (p_path.extension().to_lower()=="dds") + if (p_path.get_extension().to_lower()=="dds") return "ImageTexture"; return ""; } diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp index 43d9988de..af555b7eb 100644 --- a/modules/enet/networked_multiplayer_enet.cpp +++ b/modules/enet/networked_multiplayer_enet.cpp @@ -506,8 +506,10 @@ uint32_t NetworkedMultiplayerENet::_gen_unique_id() const { (uint32_t)OS::get_singleton()->get_unix_time(), hash ); hash = hash_djb2_one_32( (uint32_t)OS::get_singleton()->get_data_dir().hash64(), hash ); - //hash = hash_djb2_one_32( - // (uint32_t)OS::get_singleton()->get_unique_ID().hash64(), hash ); + /* + hash = hash_djb2_one_32( + (uint32_t)OS::get_singleton()->get_unique_ID().hash64(), hash ); + */ hash = hash_djb2_one_32( (uint32_t)((uint64_t)this), hash ); //rely on aslr heap hash = hash_djb2_one_32( @@ -643,12 +645,12 @@ void NetworkedMultiplayerENet::enet_compressor_destroy(void * context){ void NetworkedMultiplayerENet::_bind_methods() { - ClassDB::bind_method(_MD("create_server","port","max_clients","in_bandwidth","out_bandwidth"),&NetworkedMultiplayerENet::create_server,DEFVAL(32),DEFVAL(0),DEFVAL(0)); - ClassDB::bind_method(_MD("create_client","ip","port","in_bandwidth","out_bandwidth"),&NetworkedMultiplayerENet::create_client,DEFVAL(0),DEFVAL(0)); - ClassDB::bind_method(_MD("close_connection"),&NetworkedMultiplayerENet::close_connection); - ClassDB::bind_method(_MD("set_compression_mode","mode"),&NetworkedMultiplayerENet::set_compression_mode); - ClassDB::bind_method(_MD("get_compression_mode"),&NetworkedMultiplayerENet::get_compression_mode); - ClassDB::bind_method(_MD("set_bind_ip", "ip"),&NetworkedMultiplayerENet::set_bind_ip); + ClassDB::bind_method(D_METHOD("create_server","port","max_clients","in_bandwidth","out_bandwidth"),&NetworkedMultiplayerENet::create_server,DEFVAL(32),DEFVAL(0),DEFVAL(0)); + ClassDB::bind_method(D_METHOD("create_client","ip","port","in_bandwidth","out_bandwidth"),&NetworkedMultiplayerENet::create_client,DEFVAL(0),DEFVAL(0)); + ClassDB::bind_method(D_METHOD("close_connection"),&NetworkedMultiplayerENet::close_connection); + ClassDB::bind_method(D_METHOD("set_compression_mode","mode"),&NetworkedMultiplayerENet::set_compression_mode); + ClassDB::bind_method(D_METHOD("get_compression_mode"),&NetworkedMultiplayerENet::get_compression_mode); + ClassDB::bind_method(D_METHOD("set_bind_ip", "ip"),&NetworkedMultiplayerENet::set_bind_ip); BIND_CONSTANT( COMPRESS_NONE ); BIND_CONSTANT( COMPRESS_RANGE_CODER ); diff --git a/modules/etc1/image_etc.cpp b/modules/etc1/image_etc.cpp index 845084fef..2d883bff0 100644 --- a/modules/etc1/image_etc.cpp +++ b/modules/etc1/image_etc.cpp @@ -95,7 +95,7 @@ static void _decompress_etc(Image *p_img) { //print_line("Re Creating ETC into regular image: w "+itos(p_img->get_width())+" h "+itos(p_img->get_height())+" mm "+itos(p_img->get_mipmaps())); *p_img=Image(p_img->get_width(),p_img->get_height(),p_img->has_mipmaps(),Image::FORMAT_RGB8,dst); if (p_img->has_mipmaps()) - p_img->generate_mipmaps(true); + p_img->generate_mipmaps(); } @@ -112,16 +112,17 @@ static void _compress_etc(Image *p_img) { img.convert(Image::FORMAT_RGB8); - int mmc=img.get_mipmap_count(); - if (mmc==0) - img.generate_mipmaps(); // force mipmaps, so it works on most hardware - - PoolVector<uint8_t> res_data; PoolVector<uint8_t> dst_data; PoolVector<uint8_t>::Read r = img.get_data().read(); + int target_size = Image::get_image_data_size(p_img->get_width(),p_img->get_height(),Image::FORMAT_ETC,p_img->has_mipmaps()?-1:0); + int mmc = p_img->has_mipmaps() ? Image::get_image_required_mipmaps(p_img->get_width(),p_img->get_height(),Image::FORMAT_ETC) : 0; + + dst_data.resize(target_size); int mc=0; + int ofs=0; + PoolVector<uint8_t>::Write w=dst_data.write(); rg_etc1::etc1_pack_params pp; @@ -133,18 +134,18 @@ static void _compress_etc(Image *p_img) { int bh=MAX(imgh/4,1); const uint8_t *src = &r[img.get_mipmap_offset(i)]; int mmsize = MAX(bw,1)*MAX(bh,1)*8; - dst_data.resize(dst_data.size()+mmsize); - PoolVector<uint8_t>::Write w=dst_data.write(); - uint8_t *dst = &w[dst_data.size()-mmsize]; + + uint8_t *dst = &w[ofs]; + ofs+=mmsize; -// print_line("bh: "+itos(bh)+" bw: "+itos(bw)); + //print_line("bh: "+itos(bh)+" bw: "+itos(bw)); for(int y=0;y<bh;y++) { for(int x=0;x<bw;x++) { -// print_line("x: "+itos(x)+" y: "+itos(y)); + //print_line("x: "+itos(x)+" y: "+itos(y)); uint8_t block[4*4*4]; zeromem(block,4*4*4); diff --git a/modules/etc1/texture_loader_pkm.cpp b/modules/etc1/texture_loader_pkm.cpp index 42c9937b8..e720e1fb4 100644 --- a/modules/etc1/texture_loader_pkm.cpp +++ b/modules/etc1/texture_loader_pkm.cpp @@ -78,7 +78,7 @@ bool ResourceFormatPKM::handles_type(const String& p_type) const { String ResourceFormatPKM::get_resource_type(const String &p_path) const { - if (p_path.extension().to_lower()=="pkm") + if (p_path.get_extension().to_lower()=="pkm") return "ImageTexture"; return ""; } diff --git a/modules/gdscript/gd_compiler.cpp b/modules/gdscript/gd_compiler.cpp index 7483af298..398c2cf82 100644 --- a/modules/gdscript/gd_compiler.cpp +++ b/modules/gdscript/gd_compiler.cpp @@ -1099,7 +1099,72 @@ Error GDCompiler::_parse_block(CodeGen& codegen,const GDParser::BlockNode *p_blo switch(cf->cf_type) { + case GDParser::ControlFlowNode::CF_MATCH: { + GDParser::MatchNode *match = cf->match; + + GDParser::IdentifierNode *id = memnew(GDParser::IdentifierNode); + id->name = "#match_value"; + + // var #match_value + // copied because there is no _parse_statement :( + codegen.add_stack_identifier(id->name, p_stack_level++); + codegen.alloc_stack(p_stack_level); + new_identifiers++; + GDParser::OperatorNode *op = memnew(GDParser::OperatorNode); + op->op=GDParser::OperatorNode::OP_ASSIGN; + op->arguments.push_back(id); + op->arguments.push_back(match->val_to_match); + + int ret = _parse_expression(codegen, op, p_stack_level); + if (ret < 0) { + return ERR_PARSE_ERROR; + } + + // break address + codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); + codegen.opcodes.push_back(codegen.opcodes.size() + 3); + int break_addr = codegen.opcodes.size(); + codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); + codegen.opcodes.push_back(0); // break addr + + for (int j = 0; j < match->compiled_pattern_branches.size(); j++) { + GDParser::MatchNode::CompiledPatternBranch branch = match->compiled_pattern_branches[j]; + + // jump over continue + // jump unconditionally + // continue address + // compile the condition + int ret = _parse_expression(codegen, branch.compiled_pattern, p_stack_level); + if (ret < 0) { + return ERR_PARSE_ERROR; + } + + codegen.opcodes.push_back(GDFunction::OPCODE_JUMP_IF); + codegen.opcodes.push_back(ret); + codegen.opcodes.push_back(codegen.opcodes.size() + 3); + int continue_addr = codegen.opcodes.size(); + codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); + codegen.opcodes.push_back(0); + + + + Error err = _parse_block(codegen, branch.body, p_stack_level, p_break_addr, continue_addr); + if (err) { + return ERR_PARSE_ERROR; + } + + codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); + codegen.opcodes.push_back(break_addr); + + codegen.opcodes[continue_addr + 1] = codegen.opcodes.size(); + } + + codegen.opcodes[break_addr + 1] = codegen.opcodes.size(); + + + } break; + case GDParser::ControlFlowNode::CF_IF: { #ifdef DEBUG_ENABLED @@ -1420,9 +1485,10 @@ Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode * GDFunction *gdfunc=NULL; - //if (String(p_func->name)=="") { //initializer func - // gdfunc = &p_script->initializer; - + /* + if (String(p_func->name)=="") { //initializer func + gdfunc = &p_script->initializer; + */ //} else { //regular func p_script->member_functions[func_name]=memnew(GDFunction); gdfunc = p_script->member_functions[func_name]; @@ -1510,7 +1576,7 @@ Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode * //funciton and class if (p_class->name) { - signature+="::"+String(p_class->name)+"."+String(func_name);; + signature+="::"+String(p_class->name)+"."+String(func_name); } else { signature+="::"+String(func_name); } @@ -1729,9 +1795,14 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa } + }else { + // without extends, implicitly extend Reference + int native_idx = GDScriptLanguage::get_singleton()->get_global_map()["Reference"]; + native = GDScriptLanguage::get_singleton()->get_global_array()[native_idx]; + ERR_FAIL_COND_V(native.is_null(), ERR_BUG); + p_script->native=native; } - //print_line("Script: "+p_script->get_path()+" indices: "+itos(p_script->member_indices.size())); diff --git a/modules/gdscript/gd_compiler.h b/modules/gdscript/gd_compiler.h index dd211a852..eb6079e8e 100644 --- a/modules/gdscript/gd_compiler.h +++ b/modules/gdscript/gd_compiler.h @@ -93,7 +93,7 @@ class GDCompiler { //int get_identifier_pos(const StringName& p_dentifier) const; - HashMap<Variant,int,VariantHasher> constant_map; + HashMap<Variant,int,VariantHasher,VariantComparator> constant_map; Map<StringName,int> name_map; int get_name_map_pos(const StringName& p_identifier) { diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp index 00b080190..9dd41847d 100644 --- a/modules/gdscript/gd_editor.cpp +++ b/modules/gdscript/gd_editor.cpp @@ -28,7 +28,7 @@ /*************************************************************************/ #include "gd_script.h" #include "gd_compiler.h" -#include "globals.h" +#include "global_config.h" #include "os/file_access.h" void GDScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const { @@ -323,6 +323,16 @@ void GDScriptLanguage::get_public_constants(List<Pair<String,Variant> > *p_const pi.first="PI"; pi.second=Math_PI; p_constants->push_back(pi); + + Pair<String, Variant> infinity; + infinity.first = "INF"; + infinity.second = Math_INF; + p_constants->push_back(infinity); + + Pair<String, Variant> nan; + nan.first = "NAN"; + nan.second = Math_NAN; + p_constants->push_back(nan); } String GDScriptLanguage::make_function(const String& p_class,const String& p_name,const PoolStringArray& p_args) const { @@ -364,10 +374,12 @@ static GDCompletionIdentifier _get_type_from_variant(const Variant& p_variant) { if (p_variant.get_type()==Variant::OBJECT) { Object *obj = p_variant; if (obj) { - //if (obj->cast_to<GDNativeClass>()) { - // t.obj_type=obj->cast_to<GDNativeClass>()->get_name(); - // t.value=Variant(); - //} else { + /* + if (obj->cast_to<GDNativeClass>()) { + t.obj_type=obj->cast_to<GDNativeClass>()->get_name(); + t.value=Variant(); + } else { + */ t.obj_type=obj->get_class(); //} } @@ -671,7 +683,7 @@ static bool _guess_expression_type(GDCompletionContext& context,const GDParser:: if (!script.ends_with(".gd")) { //not a script, try find the script anyway, //may have some success - script=script.basename()+".gd"; + script=script.get_basename()+".gd"; } if (FileAccess::exists(script)) { @@ -1168,7 +1180,7 @@ static bool _guess_identifier_type(GDCompletionContext& context,int p_line,const if (!script.ends_with(".gd")) { //not a script, try find the script anyway, //may have some success - script=script.basename()+".gd"; + script=script.get_basename()+".gd"; } if (FileAccess::exists(script)) { @@ -1771,7 +1783,7 @@ static void _find_type_arguments(GDCompletionContext& context,const GDParser::No String s = E->get().name; if (!s.begins_with("autoload/")) continue; - // print_line("found "+s); + //print_line("found "+s); String name = s.get_slice("/",1); result.insert("\"/root/"+name+"\""); } @@ -1998,10 +2010,10 @@ static void _find_call_arguments(GDCompletionContext& context,const GDParser::No List<MethodInfo> methods; ClassDB::get_method_list(type,&methods); for(List<MethodInfo>::Element *E=methods.front();E;E=E->next()) { - //if (E->get().arguments.size()) - // result.insert(E->get().name+"("); - //else - // result.insert(E->get().name+"()"); + if (E->get().arguments.size()) + result.insert(E->get().name+"("); + else + result.insert(E->get().name+"()"); }*/ } break; @@ -2643,6 +2655,7 @@ Error GDScriptLanguage::lookup_code(const String& p_code, const String& p_symbol switch(p.get_completion_type()) { + case GDParser::COMPLETION_GET_NODE: case GDParser::COMPLETION_NONE: { } break; case GDParser::COMPLETION_BUILT_IN_TYPE_CONSTANT: { @@ -2832,7 +2845,7 @@ Error GDScriptLanguage::lookup_code(const String& p_code, const String& p_symbol if (!script.ends_with(".gd")) { //not a script, try find the script anyway, //may have some success - script=script.basename()+".gd"; + script=script.get_basename()+".gd"; } if (FileAccess::exists(script)) { @@ -2912,7 +2925,7 @@ Error GDScriptLanguage::lookup_code(const String& p_code, const String& p_symbol Ref<GDNativeClass> gdn = t.value; if (gdn.is_valid()) { r_result.type=ScriptLanguage::LookupResult::RESULT_CLASS_CONSTANT; - r_result.class_name=gdn->get_name();; + r_result.class_name=gdn->get_name(); r_result.class_member=p_symbol; return OK; diff --git a/modules/gdscript/gd_function.cpp b/modules/gdscript/gd_function.cpp index 665998860..0c72f6d18 100644 --- a/modules/gdscript/gd_function.cpp +++ b/modules/gdscript/gd_function.cpp @@ -171,7 +171,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a if (p_state) { //use existing (supplied) state (yielded) stack=(Variant*)p_state->stack.ptr(); - call_args=(Variant**)&p_state->stack[sizeof(Variant)*p_state->stack_size]; + call_args=(Variant**)stack + sizeof(Variant)*p_state->stack_size; line=p_state->line; ip=p_state->ip; alloca_size=p_state->stack.size(); @@ -331,8 +331,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a #endif ip+=5; - - } continue; + continue; + } case OPCODE_EXTENDS_TEST: { CHECK_SPACE(4); @@ -404,8 +404,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a *dst=extends_ok; ip+=4; - - } continue; + continue; + } case OPCODE_SET: { CHECK_SPACE(3); @@ -429,7 +429,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a } ip+=4; - } continue; + continue; + } case OPCODE_GET: { CHECK_SPACE(3); @@ -460,7 +461,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a *dst=ret; #endif ip+=4; - } continue; + continue; + } case OPCODE_SET_NAMED: { CHECK_SPACE(3); @@ -483,7 +485,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a } ip+=4; - } continue; + continue; + } case OPCODE_GET_NAMED: { @@ -518,7 +521,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a *dst=ret; #endif ip+=4; - } continue; + continue; + } case OPCODE_SET_MEMBER: { CHECK_SPACE(3); @@ -540,7 +544,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a } #endif ip+=3; - } continue; + continue; + } case OPCODE_GET_MEMBER: { CHECK_SPACE(3); @@ -557,8 +562,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a } #endif ip+=3; - - } continue; + continue; + } case OPCODE_ASSIGN: { CHECK_SPACE(3); @@ -568,8 +573,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a *dst = *src; ip+=3; - - } continue; + continue; + } case OPCODE_ASSIGN_TRUE: { CHECK_SPACE(2); @@ -578,7 +583,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a *dst = true; ip+=2; - } continue; + continue; + } case OPCODE_ASSIGN_FALSE: { CHECK_SPACE(2); @@ -587,7 +593,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a *dst = false; ip+=2; - } continue; + continue; + } case OPCODE_CONSTRUCT: { CHECK_SPACE(2); @@ -612,7 +619,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a ip+=4+argc; //construct a basic type - } continue; + continue; + } case OPCODE_CONSTRUCT_ARRAY: { CHECK_SPACE(1); @@ -632,8 +640,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a *dst=array; ip+=3+argc; - - } continue; + continue; + } case OPCODE_CONSTRUCT_DICTIONARY: { CHECK_SPACE(1); @@ -655,8 +663,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a *dst=dict; ip+=3+argc*2; - - } continue; + continue; + } case OPCODE_CALL_RETURN: case OPCODE_CALL: { @@ -717,7 +725,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a err.argument-=1; } } - } if (methodstr=="free") { + } else if (methodstr=="free") { if (err.error==Variant::CallError::CALL_ERROR_INVALID_METHOD) { @@ -737,8 +745,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a //_call_func(NULL,base,*methodname,ip,argc,p_instance,stack); ip+=argc+1; - - } continue; + continue; + } case OPCODE_CALL_BUILT_IN: { CHECK_SPACE(4); @@ -775,12 +783,12 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a break; } ip+=argc+1; - - } continue; + continue; + } case OPCODE_CALL_SELF: { - - } break; + break; + } case OPCODE_CALL_SELF_BASE: { CHECK_SPACE(2); @@ -857,8 +865,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a } ip+=4+argc; - - } continue; + continue; + } case OPCODE_YIELD: case OPCODE_YIELD_SIGNAL: { @@ -938,8 +946,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a } exit_ok=true; - - } break; + break; + } case OPCODE_YIELD_RESUME: { CHECK_SPACE(2); @@ -950,8 +958,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a GET_VARIANT_PTR(result,1); *result=p_state->result; ip+=2; - - } continue; + continue; + } case OPCODE_JUMP: { CHECK_SPACE(2); @@ -959,8 +967,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a ERR_BREAK(to<0 || to>_code_size); ip=to; - - } continue; + continue; + } case OPCODE_JUMP_IF: { CHECK_SPACE(3); @@ -983,7 +991,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a continue; } ip+=3; - } continue; + continue; + } case OPCODE_JUMP_IF_NOT: { CHECK_SPACE(3); @@ -1006,21 +1015,22 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a continue; } ip+=3; - } continue; + continue; + } case OPCODE_JUMP_TO_DEF_ARGUMENT: { CHECK_SPACE(2); ip=_default_arg_ptr[defarg]; - - } continue; + continue; + } case OPCODE_RETURN: { CHECK_SPACE(2); GET_VARIANT_PTR(r,1); retvalue=*r; exit_ok=true; - - } break; + break; + } case OPCODE_ITERATE_BEGIN: { CHECK_SPACE(8); //space for this an regular iterate @@ -1050,8 +1060,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a ip+=5; //skip regular iterate which is always next - - } continue; + continue; + } case OPCODE_ITERATE: { CHECK_SPACE(4); @@ -1079,7 +1089,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a } ip+=5; //loop again - } continue; + continue; + } case OPCODE_ASSERT: { CHECK_SPACE(2); GET_VARIANT_PTR(test,1); @@ -1105,7 +1116,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a #endif ip+=2; - } continue; + continue; + } case OPCODE_BREAKPOINT: { #ifdef DEBUG_ENABLED if (ScriptDebugger::get_singleton()) { @@ -1113,7 +1125,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a } #endif ip+=1; - } continue; + continue; + } case OPCODE_LINE: { CHECK_SPACE(2); @@ -1142,17 +1155,19 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a ScriptDebugger::get_singleton()->line_poll(); } - } continue; + continue; + } case OPCODE_END: { exit_ok=true; break; - } break; + } default: { err_text="Illegal opcode "+itos(_code_ptr[ip])+" at address "+itos(ip); - } break; + break; + } } @@ -1475,8 +1490,8 @@ Variant GDFunctionState::resume(const Variant& p_arg) { void GDFunctionState::_bind_methods() { - ClassDB::bind_method(_MD("resume:Variant","arg"),&GDFunctionState::resume,DEFVAL(Variant())); - ClassDB::bind_method(_MD("is_valid"),&GDFunctionState::is_valid); + ClassDB::bind_method(D_METHOD("resume:Variant","arg"),&GDFunctionState::resume,DEFVAL(Variant())); + ClassDB::bind_method(D_METHOD("is_valid"),&GDFunctionState::is_valid); ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"_signal_callback",&GDFunctionState::_signal_callback,MethodInfo("_signal_callback")); } diff --git a/modules/gdscript/gd_functions.cpp b/modules/gdscript/gd_functions.cpp index 1c41b2e73..d0fc24173 100644 --- a/modules/gdscript/gd_functions.cpp +++ b/modules/gdscript/gd_functions.cpp @@ -28,7 +28,7 @@ /*************************************************************************/ #include "gd_functions.h" #include "math_funcs.h" -#include "object_type_db.h" +#include "class_db.h" #include "reference.h" #include "gd_script.h" #include "func_ref.h" @@ -159,85 +159,85 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va case MATH_SIN: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::sin(*p_args[0]); + r_ret=Math::sin((double)*p_args[0]); } break; case MATH_COS: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::cos(*p_args[0]); + r_ret=Math::cos((double)*p_args[0]); } break; case MATH_TAN: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::tan(*p_args[0]); + r_ret=Math::tan((double)*p_args[0]); } break; case MATH_SINH: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::sinh(*p_args[0]); + r_ret=Math::sinh((double)*p_args[0]); } break; case MATH_COSH: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::cosh(*p_args[0]); + r_ret=Math::cosh((double)*p_args[0]); } break; case MATH_TANH: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::tanh(*p_args[0]); + r_ret=Math::tanh((double)*p_args[0]); } break; case MATH_ASIN: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::asin(*p_args[0]); + r_ret=Math::asin((double)*p_args[0]); } break; case MATH_ACOS: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::acos(*p_args[0]); + r_ret=Math::acos((double)*p_args[0]); } break; case MATH_ATAN: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::atan(*p_args[0]); + r_ret=Math::atan((double)*p_args[0]); } break; case MATH_ATAN2: { VALIDATE_ARG_COUNT(2); VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - r_ret=Math::atan2(*p_args[0],*p_args[1]); + r_ret=Math::atan2((double)*p_args[0],(double)*p_args[1]); } break; case MATH_SQRT: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::sqrt(*p_args[0]); + r_ret=Math::sqrt((double)*p_args[0]); } break; case MATH_FMOD: { VALIDATE_ARG_COUNT(2); VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - r_ret=Math::fmod(*p_args[0],*p_args[1]); + r_ret=Math::fmod((double)*p_args[0],(double)*p_args[1]); } break; case MATH_FPOSMOD: { VALIDATE_ARG_COUNT(2); VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - r_ret=Math::fposmod(*p_args[0],*p_args[1]); + r_ret=Math::fposmod((double)*p_args[0],(double)*p_args[1]); } break; case MATH_FLOOR: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::floor(*p_args[0]); + r_ret=Math::floor((double)*p_args[0]); } break; case MATH_CEIL: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::ceil(*p_args[0]); + r_ret=Math::ceil((double)*p_args[0]); } break; case MATH_ROUND: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::round(*p_args[0]); + r_ret=Math::round((double)*p_args[0]); } break; case MATH_ABS: { VALIDATE_ARG_COUNT(1); @@ -247,7 +247,7 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va r_ret=ABS(i); } else if (p_args[0]->get_type()==Variant::REAL) { - real_t r = *p_args[0]; + double r = *p_args[0]; r_ret=Math::abs(r); } else { @@ -279,58 +279,58 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va VALIDATE_ARG_COUNT(2); VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - r_ret=Math::pow(*p_args[0],*p_args[1]); + r_ret=Math::pow((double)*p_args[0],(double)*p_args[1]); } break; case MATH_LOG: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::log(*p_args[0]); + r_ret=Math::log((double)*p_args[0]); } break; case MATH_EXP: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::exp(*p_args[0]); + r_ret=Math::exp((double)*p_args[0]); } break; case MATH_ISNAN: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::is_nan(*p_args[0]); + r_ret=Math::is_nan((double)*p_args[0]); } break; case MATH_ISINF: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::is_inf(*p_args[0]); + r_ret=Math::is_inf((double)*p_args[0]); } break; case MATH_EASE: { VALIDATE_ARG_COUNT(2); VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - r_ret=Math::ease(*p_args[0],*p_args[1]); + r_ret=Math::ease((double)*p_args[0],(double)*p_args[1]); } break; case MATH_DECIMALS: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::step_decimals(*p_args[0]); + r_ret=Math::step_decimals((double)*p_args[0]); } break; case MATH_STEPIFY: { VALIDATE_ARG_COUNT(2); VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - r_ret=Math::stepify(*p_args[0],*p_args[1]); + r_ret=Math::stepify((double)*p_args[0],(double)*p_args[1]); } break; case MATH_LERP: { VALIDATE_ARG_COUNT(3); VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); - r_ret=Math::lerp(*p_args[0],*p_args[1],*p_args[2]); + r_ret=Math::lerp((double)*p_args[0],(double)*p_args[1],(double)*p_args[2]); } break; case MATH_DECTIME: { VALIDATE_ARG_COUNT(3); VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); - r_ret=Math::dectime(*p_args[0],*p_args[1],*p_args[2]); + r_ret=Math::dectime((double)*p_args[0],(double)*p_args[1],(double)*p_args[2]); } break; case MATH_RANDOMIZE: { Math::randomize(); @@ -346,19 +346,19 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va VALIDATE_ARG_COUNT(2); VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - r_ret=Math::random(*p_args[0],*p_args[1]); + r_ret=Math::random((double)*p_args[0],(double)*p_args[1]); } break; case MATH_SEED: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - uint32_t seed=*p_args[0]; + uint64_t seed=*p_args[0]; Math::seed(seed); r_ret=Variant(); } break; case MATH_RANDSEED: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - uint32_t seed=*p_args[0]; + uint64_t seed=*p_args[0]; int ret = Math::rand_from_seed(&seed); Array reta; reta.push_back(ret); @@ -369,22 +369,22 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va case MATH_DEG2RAD: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::deg2rad(*p_args[0]); + r_ret=Math::deg2rad((double)*p_args[0]); } break; case MATH_RAD2DEG: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::rad2deg(*p_args[0]); + r_ret=Math::rad2deg((double)*p_args[0]); } break; case MATH_LINEAR2DB: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::linear2db(*p_args[0]); + r_ret=Math::linear2db((double)*p_args[0]); } break; case MATH_DB2LINEAR: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::db2linear(*p_args[0]); + r_ret=Math::db2linear((double)*p_args[0]); } break; case LOGIC_MAX: { VALIDATE_ARG_COUNT(2); @@ -555,7 +555,7 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va String str; for(int i=0;i<p_arg_count;i++) { - String os = p_args[i]->operator String();; + String os = p_args[i]->operator String(); if (i==0) str=os; diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp index 6aed7c949..5147ccd63 100644 --- a/modules/gdscript/gd_parser.cpp +++ b/modules/gdscript/gd_parser.cpp @@ -225,8 +225,8 @@ bool GDParser::_get_completable_identifier(CompletionType p_type,StringName& ide GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_allow_assign,bool p_parsing_constant) { -// Vector<Node*> expressions; -// Vector<OperatorNode::Operator> operators; + //Vector<Node*> expressions; + //Vector<OperatorNode::Operator> operators; Vector<Expression> expression; @@ -375,6 +375,22 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_ constant->value=Math_PI; tokenizer->advance(); expr=constant; + } + else if (tokenizer->get_token() == GDTokenizer::TK_CONST_INF) { + + //constant defined by tokenizer + ConstantNode *constant = alloc_node<ConstantNode>(); + constant->value = Math_INF; + tokenizer->advance(); + expr = constant; + } + else if (tokenizer->get_token() == GDTokenizer::TK_CONST_NAN) { + + //constant defined by tokenizer + ConstantNode *constant = alloc_node<ConstantNode>(); + constant->value = Math_NAN; + tokenizer->advance(); + expr = constant; } else if (tokenizer->get_token()==GDTokenizer::TK_PR_PRELOAD) { //constant defined by tokenizer @@ -386,21 +402,42 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_ tokenizer->advance(); String path; + bool found_constant = false; bool valid = false; + ConstantNode *cn; + Node *subexpr = _parse_and_reduce_expression(p_parent, p_static); if (subexpr) { if (subexpr->type == Node::TYPE_CONSTANT) { - ConstantNode *cn = static_cast<ConstantNode*>(subexpr); - if (cn->value.get_type() == Variant::STRING) { - valid = true; - path = (String) cn->value; + cn = static_cast<ConstantNode*>(subexpr); + found_constant = true; + } + if (subexpr->type == Node::TYPE_IDENTIFIER) { + IdentifierNode *in = static_cast<IdentifierNode*>(subexpr); + Vector<ClassNode::Constant> ce = current_class->constant_expressions; + + // Try to find the constant expression by the identifier + for(int i=0; i < ce.size(); ++i){ + if(ce[i].identifier == in->name) { + if(ce[i].expression->type == Node::TYPE_CONSTANT) { + cn = static_cast<ConstantNode*>(ce[i].expression); + found_constant = true; + } + } } } + + if (found_constant && cn->value.get_type() == Variant::STRING) { + valid = true; + path = (String) cn->value; + } } + if (!valid) { _set_error("expected string constant as 'preload' argument."); return NULL; } + if (!path.is_abs_path() && base_path!="") path=base_path+"/"+path; path = path.replace("///","//").simplify_path(); @@ -643,7 +680,7 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_ case GDTokenizer::TK_OP_ADD: e.op=OperatorNode::OP_POS; break; case GDTokenizer::TK_OP_SUB: e.op=OperatorNode::OP_NEG; break; case GDTokenizer::TK_OP_NOT: e.op=OperatorNode::OP_NOT; break; - case GDTokenizer::TK_OP_BIT_INVERT: e.op=OperatorNode::OP_BIT_INVERT;; break; + case GDTokenizer::TK_OP_BIT_INVERT: e.op=OperatorNode::OP_BIT_INVERT; break; default: {} } @@ -724,6 +761,7 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_ }; Node *key=NULL; + Set<Variant> keys; DictExpect expecting=DICT_EXPECT_KEY; @@ -819,6 +857,16 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_ return NULL; expecting=DICT_EXPECT_COMMA; + if (key->type == GDParser::Node::TYPE_CONSTANT) { + Variant const& keyName = static_cast<const GDParser::ConstantNode*>(key)->value; + + if (keys.has(keyName)) { + _set_error("Duplicate key found in Dictionary literal"); + return NULL; + } + keys.insert(keyName); + } + DictionaryNode::Pair pair; pair.key=key; pair.value=value; @@ -1032,8 +1080,8 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_ case GDTokenizer::TK_OP_ASSIGN_MUL: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_MUL ; break; case GDTokenizer::TK_OP_ASSIGN_DIV: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_DIV ; break; case GDTokenizer::TK_OP_ASSIGN_MOD: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_MOD ; break; - case GDTokenizer::TK_OP_ASSIGN_SHIFT_LEFT: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_SHIFT_LEFT; ; break; - case GDTokenizer::TK_OP_ASSIGN_SHIFT_RIGHT: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_SHIFT_RIGHT; ; break; + case GDTokenizer::TK_OP_ASSIGN_SHIFT_LEFT: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_SHIFT_LEFT; break; + case GDTokenizer::TK_OP_ASSIGN_SHIFT_RIGHT: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_SHIFT_RIGHT; break; case GDTokenizer::TK_OP_ASSIGN_BIT_AND: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_BIT_AND ; break; case GDTokenizer::TK_OP_ASSIGN_BIT_OR: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_BIT_OR ; break; case GDTokenizer::TK_OP_ASSIGN_BIT_XOR: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_BIT_XOR ; break; @@ -1679,6 +1727,541 @@ bool GDParser::_recover_from_completion() { return true; } +GDParser::PatternNode *GDParser::_parse_pattern(bool p_static) +{ + + PatternNode *pattern = alloc_node<PatternNode>(); + + GDTokenizer::Token token = tokenizer->get_token(); + if (error_set) + return NULL; + + if (token == GDTokenizer::TK_EOF) { + return NULL; + } + + switch (token) { + // array + case GDTokenizer::TK_BRACKET_OPEN: { + tokenizer->advance(); + pattern->pt_type = GDParser::PatternNode::PT_ARRAY; + while (true) { + + if (tokenizer->get_token() == GDTokenizer::TK_BRACKET_CLOSE) { + tokenizer->advance(); + break; + } + + if (tokenizer->get_token() == GDTokenizer::TK_PERIOD && tokenizer->get_token(1) == GDTokenizer::TK_PERIOD) { + // match everything + tokenizer->advance(2); + PatternNode *sub_pattern = alloc_node<PatternNode>(); + sub_pattern->pt_type = GDParser::PatternNode::PT_IGNORE_REST; + pattern->array.push_back(sub_pattern); + if (tokenizer->get_token() == GDTokenizer::TK_COMMA && tokenizer->get_token(1) == GDTokenizer::TK_BRACKET_CLOSE) { + tokenizer->advance(2); + break; + } else if (tokenizer->get_token() == GDTokenizer::TK_BRACKET_CLOSE) { + tokenizer->advance(1); + break; + } else { + _set_error("'..' pattern only allowed at the end of an array pattern"); + return NULL; + } + } + + PatternNode *sub_pattern = _parse_pattern(p_static); + if (!sub_pattern) { + return NULL; + } + + pattern->array.push_back(sub_pattern); + + if (tokenizer->get_token() == GDTokenizer::TK_COMMA) { + tokenizer->advance(); + continue; + } else if (tokenizer->get_token() == GDTokenizer::TK_BRACKET_CLOSE) { + tokenizer->advance(); + break; + } else { + _set_error("Not a valid pattern"); + return NULL; + } + } + } break; + // bind + case GDTokenizer::TK_PR_VAR: { + tokenizer->advance(); + pattern->pt_type = GDParser::PatternNode::PT_BIND; + pattern->bind = tokenizer->get_token_identifier(); + tokenizer->advance(); + } break; + // dictionary + case GDTokenizer::TK_CURLY_BRACKET_OPEN: { + tokenizer->advance(); + pattern->pt_type = GDParser::PatternNode::PT_DICTIONARY; + while (true) { + + if (tokenizer->get_token() == GDTokenizer::TK_CURLY_BRACKET_CLOSE) { + tokenizer->advance(); + break; + } + + if (tokenizer->get_token() == GDTokenizer::TK_PERIOD && tokenizer->get_token(1) == GDTokenizer::TK_PERIOD) { + // match everything + tokenizer->advance(2); + PatternNode *sub_pattern = alloc_node<PatternNode>(); + sub_pattern->pt_type = PatternNode::PT_IGNORE_REST; + pattern->array.push_back(sub_pattern); + if (tokenizer->get_token() == GDTokenizer::TK_COMMA && tokenizer->get_token(1) == GDTokenizer::TK_CURLY_BRACKET_CLOSE) { + tokenizer->advance(2); + break; + } else if (tokenizer->get_token() == GDTokenizer::TK_CURLY_BRACKET_CLOSE) { + tokenizer->advance(1); + break; + } else { + _set_error("'..' pattern only allowed at the end of an dictionary pattern"); + return NULL; + } + } + + Node *key = _parse_and_reduce_expression(pattern, p_static); + if (!key) { + _set_error("Not a valid key in pattern"); + return NULL; + } + + if (key->type != GDParser::Node::TYPE_CONSTANT) { + _set_error("Not a constant expression as key"); + return NULL; + } + + if (tokenizer->get_token() == GDTokenizer::TK_COLON) { + tokenizer->advance(); + + PatternNode *value = _parse_pattern(p_static); + if (!value) { + _set_error("Expected pattern in dictionary value"); + return NULL; + } + + pattern->dictionary.insert(static_cast<ConstantNode*>(key), value); + } else { + pattern->dictionary.insert(static_cast<ConstantNode*>(key), NULL); + } + + + if (tokenizer->get_token() == GDTokenizer::TK_COMMA) { + tokenizer->advance(); + continue; + } else if (tokenizer->get_token() == GDTokenizer::TK_CURLY_BRACKET_CLOSE) { + tokenizer->advance(); + break; + } else { + _set_error("Not a valid pattern"); + return NULL; + } + } + } break; + case GDTokenizer::TK_WILDCARD: { + tokenizer->advance(); + pattern->pt_type = PatternNode::PT_WILDCARD; + } break; + // all the constants like strings and numbers + default: { + Node *value = _parse_and_reduce_expression(pattern, p_static); + if (error_set) { + return NULL; + } + + if (value->type != Node::TYPE_IDENTIFIER && value->type != Node::TYPE_CONSTANT) { + _set_error("Only constant expressions or variables allowed in a pattern"); + return NULL; + } + + pattern->pt_type = PatternNode::PT_CONSTANT; + pattern->constant = value; + } break; + } + + return pattern; +} + +void GDParser::_parse_pattern_block(BlockNode *p_block, Vector<PatternBranchNode*> &p_branches, bool p_static) +{ + int indent_level = tab_level.back()->get(); + + while (true) { + + while (tokenizer->get_token() == GDTokenizer::TK_NEWLINE && _parse_newline()); + + // GDTokenizer::Token token = tokenizer->get_token(); + if (error_set) + return; + + if (indent_level > tab_level.back()->get()) { + return; // go back a level + } + + if (pending_newline!=-1) { + pending_newline=-1; + } + + PatternBranchNode *branch = alloc_node<PatternBranchNode>(); + + branch->patterns.push_back(_parse_pattern(p_static)); + if (!branch->patterns[0]) { + return; + } + + while (tokenizer->get_token() == GDTokenizer::TK_COMMA) { + tokenizer->advance(); + branch->patterns.push_back(_parse_pattern(p_static)); + if (!branch->patterns[branch->patterns.size() - 1]) { + return; + } + } + + if(!_enter_indent_block()) { + _set_error("Expected block in pattern branch"); + return; + } + + branch->body = alloc_node<BlockNode>(); + branch->body->parent_block = p_block; + p_block->sub_blocks.push_back(branch->body); + current_block = branch->body; + + _parse_block(branch->body, p_static); + + current_block = p_block; + + p_branches.push_back(branch); + } +} + + +void GDParser::_generate_pattern(PatternNode *p_pattern, Node *p_node_to_match, Node *&p_resulting_node, Map<StringName, Node*> &p_bindings) +{ + switch (p_pattern->pt_type) { + case PatternNode::PT_CONSTANT: { + + // typecheck + BuiltInFunctionNode *typeof_node = alloc_node<BuiltInFunctionNode>(); + typeof_node->function = GDFunctions::TYPE_OF; + + OperatorNode *typeof_match_value = alloc_node<OperatorNode>(); + typeof_match_value->op = OperatorNode::OP_CALL; + typeof_match_value->arguments.push_back(typeof_node); + typeof_match_value->arguments.push_back(p_node_to_match); + + OperatorNode *typeof_pattern_value = alloc_node<OperatorNode>(); + typeof_pattern_value->op = OperatorNode::OP_CALL; + typeof_pattern_value->arguments.push_back(typeof_node); + typeof_pattern_value->arguments.push_back(p_pattern->constant); + + OperatorNode *type_comp = alloc_node<OperatorNode>(); + type_comp->op = OperatorNode::OP_EQUAL; + type_comp->arguments.push_back(typeof_match_value); + type_comp->arguments.push_back(typeof_pattern_value); + + + // comare the actual values + OperatorNode *value_comp = alloc_node<OperatorNode>(); + value_comp->op = OperatorNode::OP_EQUAL; + value_comp->arguments.push_back(p_pattern->constant); + value_comp->arguments.push_back(p_node_to_match); + + + OperatorNode *comparison = alloc_node<OperatorNode>(); + comparison->op = OperatorNode::OP_AND; + comparison->arguments.push_back(type_comp); + comparison->arguments.push_back(value_comp); + + p_resulting_node = comparison; + + } break; + case PatternNode::PT_BIND: { + p_bindings[p_pattern->bind] = p_node_to_match; + + // a bind always matches + ConstantNode *true_value = alloc_node<ConstantNode>(); + true_value->value = Variant(true); + p_resulting_node = true_value; + } break; + case PatternNode::PT_ARRAY: { + + bool open_ended = false; + + if (p_pattern->array.size() > 0) { + if (p_pattern->array[p_pattern->array.size() - 1]->pt_type == PatternNode::PT_IGNORE_REST) { + open_ended = true; + } + } + + // typeof(value_to_match) == TYPE_ARRAY && value_to_match.size() >= length + // typeof(value_to_match) == TYPE_ARRAY && value_to_match.size() == length + + { + // typecheck + BuiltInFunctionNode *typeof_node = alloc_node<BuiltInFunctionNode>(); + typeof_node->function = GDFunctions::TYPE_OF; + + OperatorNode *typeof_match_value = alloc_node<OperatorNode>(); + typeof_match_value->op = OperatorNode::OP_CALL; + typeof_match_value->arguments.push_back(typeof_node); + typeof_match_value->arguments.push_back(p_node_to_match); + + IdentifierNode *typeof_array = alloc_node<IdentifierNode>(); + typeof_array->name = "TYPE_ARRAY"; + + OperatorNode *type_comp = alloc_node<OperatorNode>(); + type_comp->op = OperatorNode::OP_EQUAL; + type_comp->arguments.push_back(typeof_match_value); + type_comp->arguments.push_back(typeof_array); + + + // size + ConstantNode *length = alloc_node<ConstantNode>(); + length->value = Variant(open_ended ? p_pattern->array.size() - 1 : p_pattern->array.size()); + + OperatorNode *call = alloc_node<OperatorNode>(); + call->op = OperatorNode::OP_CALL; + call->arguments.push_back(p_node_to_match); + + IdentifierNode *size = alloc_node<IdentifierNode>(); + size->name = "size"; + call->arguments.push_back(size); + + OperatorNode *length_comparison = alloc_node<OperatorNode>(); + length_comparison->op = open_ended ? OperatorNode::OP_GREATER_EQUAL : OperatorNode::OP_EQUAL; + length_comparison->arguments.push_back(call); + length_comparison->arguments.push_back(length); + + OperatorNode *type_and_length_comparison = alloc_node<OperatorNode>(); + type_and_length_comparison->op = OperatorNode::OP_AND; + type_and_length_comparison->arguments.push_back(type_comp); + type_and_length_comparison->arguments.push_back(length_comparison); + + p_resulting_node = type_and_length_comparison; + } + + + + for (int i = 0; i < p_pattern->array.size(); i++) { + PatternNode *pattern = p_pattern->array[i]; + + Node *condition = NULL; + + ConstantNode *index = alloc_node<ConstantNode>(); + index->value = Variant(i); + + OperatorNode *indexed_value = alloc_node<OperatorNode>(); + indexed_value->op = OperatorNode::OP_INDEX; + indexed_value->arguments.push_back(p_node_to_match); + indexed_value->arguments.push_back(index); + + _generate_pattern(pattern, indexed_value, condition, p_bindings); + + // concatenate all the patterns with && + OperatorNode *and_node = alloc_node<OperatorNode>(); + and_node->op = OperatorNode::OP_AND; + and_node->arguments.push_back(p_resulting_node); + and_node->arguments.push_back(condition); + + p_resulting_node = and_node; + } + + + } break; + case PatternNode::PT_DICTIONARY: { + + bool open_ended = false; + + if (p_pattern->array.size() > 0) { + open_ended = true; + } + + // typeof(value_to_match) == TYPE_DICTIONARY && value_to_match.size() >= length + // typeof(value_to_match) == TYPE_DICTIONARY && value_to_match.size() == length + + + { + // typecheck + BuiltInFunctionNode *typeof_node = alloc_node<BuiltInFunctionNode>(); + typeof_node->function = GDFunctions::TYPE_OF; + + OperatorNode *typeof_match_value = alloc_node<OperatorNode>(); + typeof_match_value->op = OperatorNode::OP_CALL; + typeof_match_value->arguments.push_back(typeof_node); + typeof_match_value->arguments.push_back(p_node_to_match); + + IdentifierNode *typeof_dictionary = alloc_node<IdentifierNode>(); + typeof_dictionary->name = "TYPE_DICTIONARY"; + + OperatorNode *type_comp = alloc_node<OperatorNode>(); + type_comp->op = OperatorNode::OP_EQUAL; + type_comp->arguments.push_back(typeof_match_value); + type_comp->arguments.push_back(typeof_dictionary); + + // size + ConstantNode *length = alloc_node<ConstantNode>(); + length->value = Variant(open_ended ? p_pattern->dictionary.size() - 1 : p_pattern->dictionary.size()); + + OperatorNode *call = alloc_node<OperatorNode>(); + call->op = OperatorNode::OP_CALL; + call->arguments.push_back(p_node_to_match); + + IdentifierNode *size = alloc_node<IdentifierNode>(); + size->name = "size"; + call->arguments.push_back(size); + + OperatorNode *length_comparison = alloc_node<OperatorNode>(); + length_comparison->op = open_ended ? OperatorNode::OP_GREATER_EQUAL : OperatorNode::OP_EQUAL; + length_comparison->arguments.push_back(call); + length_comparison->arguments.push_back(length); + + OperatorNode *type_and_length_comparison = alloc_node<OperatorNode>(); + type_and_length_comparison->op = OperatorNode::OP_AND; + type_and_length_comparison->arguments.push_back(type_comp); + type_and_length_comparison->arguments.push_back(length_comparison); + + p_resulting_node = type_and_length_comparison; + } + + + + for (Map<ConstantNode*, PatternNode*>::Element *e = p_pattern->dictionary.front(); e; e = e->next()) { + + Node *condition = NULL; + + // chech for has, then for pattern + + IdentifierNode *has = alloc_node<IdentifierNode>(); + has->name = "has"; + + OperatorNode *has_call = alloc_node<OperatorNode>(); + has_call->op = OperatorNode::OP_CALL; + has_call->arguments.push_back(p_node_to_match); + has_call->arguments.push_back(has); + has_call->arguments.push_back(e->key()); + + + if (e->value()) { + + OperatorNode *indexed_value = alloc_node<OperatorNode>(); + indexed_value->op = OperatorNode::OP_INDEX; + indexed_value->arguments.push_back(p_node_to_match); + indexed_value->arguments.push_back(e->key()); + + _generate_pattern(e->value(), indexed_value, condition, p_bindings); + + OperatorNode *has_and_pattern = alloc_node<OperatorNode>(); + has_and_pattern->op = OperatorNode::OP_AND; + has_and_pattern->arguments.push_back(has_call); + has_and_pattern->arguments.push_back(condition); + + condition = has_and_pattern; + + } else { + condition = has_call; + } + + + + // concatenate all the patterns with && + OperatorNode *and_node = alloc_node<OperatorNode>(); + and_node->op = OperatorNode::OP_AND; + and_node->arguments.push_back(p_resulting_node); + and_node->arguments.push_back(condition); + + p_resulting_node = and_node; + } + + } break; + case PatternNode::PT_IGNORE_REST: + case PatternNode::PT_WILDCARD: { + // simply generate a `true` + ConstantNode *true_value = alloc_node<ConstantNode>(); + true_value->value = Variant(true); + p_resulting_node = true_value; + } break; + default: { + + } break; + } +} + +void GDParser::_transform_match_statment(BlockNode *p_block, MatchNode *p_match_statement) +{ + IdentifierNode *id = alloc_node<IdentifierNode>(); + id->name = "#match_value"; + + for (int i = 0; i < p_match_statement->branches.size(); i++) { + + PatternBranchNode *branch = p_match_statement->branches[i]; + + MatchNode::CompiledPatternBranch compiled_branch; + compiled_branch.compiled_pattern = NULL; + + Map<StringName, Node*> binding; + + for (int j = 0; j < branch->patterns.size(); j++) { + PatternNode *pattern = branch->patterns[j]; + + Map<StringName, Node*> bindings; + Node *resulting_node; + _generate_pattern(pattern, id, resulting_node, bindings); + + if (!binding.empty() && !bindings.empty()) { + _set_error("Multipatterns can't contain bindings"); + return; + } else { + binding = bindings; + } + + if (compiled_branch.compiled_pattern) { + OperatorNode *or_node = alloc_node<OperatorNode>(); + or_node->op = OperatorNode::OP_OR; + or_node->arguments.push_back(compiled_branch.compiled_pattern); + or_node->arguments.push_back(resulting_node); + + compiled_branch.compiled_pattern = or_node; + } else { + // single pattern | first one + compiled_branch.compiled_pattern = resulting_node; + } + + } + + + // prepare the body ...hehe + for (Map<StringName, Node*>::Element *e = binding.front(); e; e = e->next()) { + LocalVarNode *local_var = alloc_node<LocalVarNode>(); + local_var->name = e->key(); + local_var->assign = e->value(); + + + IdentifierNode *id = alloc_node<IdentifierNode>(); + id->name = local_var->name; + + OperatorNode *op = alloc_node<OperatorNode>(); + op->op=OperatorNode::OP_ASSIGN; + op->arguments.push_back(id); + op->arguments.push_back(local_var->assign); + + branch->body->statements.push_front(op); + branch->body->statements.push_front(local_var); + } + + compiled_branch.body = branch->body; + + + p_match_statement->compiled_pattern_branches.push_back(compiled_branch); + } + +} + void GDParser::_parse_block(BlockNode *p_block,bool p_static) { int indent_level = tab_level.back()->get(); @@ -1762,6 +2345,24 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) { } StringName n = tokenizer->get_token_identifier(); tokenizer->advance(); + if (current_function){ + for (int i=0;i<current_function->arguments.size();i++){ + if (n == current_function->arguments[i]){ + _set_error("Variable '"+String(n)+"' already defined in the scope (at line: "+itos(current_function->line)+")."); + return; + } + } + } + BlockNode *check_block = p_block; + while (check_block){ + for (int i=0;i<check_block->variables.size();i++){ + if (n == check_block->variables[i]){ + _set_error("Variable '"+String(n)+"' already defined in the scope (at line: "+itos(check_block->variable_lines[i])+")."); + return; + } + } + check_block = check_block->parent_block; + } p_block->variables.push_back(n); //line? p_block->variable_lines.push_back(tokenizer->get_token_line()); @@ -2013,7 +2614,7 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) { Vector<Node*> args; Vector<double> constants; - bool constant=true; + bool constant=false; for(int i=1;i<op->arguments.size();i++) { args.push_back(op->arguments[i]); @@ -2021,13 +2622,14 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) { ConstantNode *c = static_cast<ConstantNode*>(op->arguments[i]); if (c->value.get_type()==Variant::REAL || c->value.get_type()==Variant::INT) { constants.push_back(c->value); - } else { - constant=false; + constant=true; } + } else { + constant=false; } } - if (args.size()>0 || args.size()<4) { + if (args.size()>0 && args.size()<4) { if (constant) { @@ -2079,7 +2681,14 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) { } current_block=cf_for->body; + + // this is for checking variable for redefining + // inside this _parse_block + cf_for->body->variables.push_back(id->name); + cf_for->body->variable_lines.push_back(id->line); _parse_block(cf_for->body,p_static); + cf_for->body->variables.remove(0); + cf_for->body->variable_lines.remove(0); current_block=p_block; if (error_set) @@ -2141,6 +2750,46 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) { } break; + case GDTokenizer::TK_CF_MATCH: { + + tokenizer->advance(); + + MatchNode *match_node = alloc_node<MatchNode>(); + + Node *val_to_match = _parse_and_reduce_expression(p_block, p_static); + + if (!val_to_match) { + if (_recover_from_completion()) { + break; + } + return; + } + + match_node->val_to_match = val_to_match; + + if (!_enter_indent_block()) { + _set_error("Expected indented pattern matching block after 'match'"); + return; + } + + BlockNode *compiled_branches = alloc_node<BlockNode>(); + compiled_branches->parent_block = p_block; + compiled_branches->parent_class = p_block->parent_class; + + p_block->sub_blocks.push_back(compiled_branches); + + _parse_pattern_block(compiled_branches, match_node->branches, p_static); + + _transform_match_statment(compiled_branches, match_node); + + ControlFlowNode *match_cf_node = alloc_node<ControlFlowNode>(); + match_cf_node->cf_type = ControlFlowNode::CF_MATCH; + match_cf_node->match = match_node; + + p_block->statements.push_back(match_cf_node); + + _end_statement(); + } break; case GDTokenizer::TK_PR_ASSERT: { tokenizer->advance(); diff --git a/modules/gdscript/gd_parser.h b/modules/gdscript/gd_parser.h index e8f5f0f98..7968bf85d 100644 --- a/modules/gdscript/gd_parser.h +++ b/modules/gdscript/gd_parser.h @@ -258,6 +258,44 @@ public: Vector<Node*> arguments; OperatorNode() { type=TYPE_OPERATOR; } }; + + + struct PatternNode : public Node { + + enum PatternType { + PT_CONSTANT, + PT_BIND, + PT_DICTIONARY, + PT_ARRAY, + PT_IGNORE_REST, + PT_WILDCARD + }; + + PatternType pt_type; + + Node *constant; + StringName bind; + Map<ConstantNode*, PatternNode*> dictionary; + Vector<PatternNode*> array; + + }; + + struct PatternBranchNode : public Node { + Vector<PatternNode*> patterns; + BlockNode *body; + }; + + struct MatchNode : public Node { + Node *val_to_match; + Vector<PatternBranchNode*> branches; + + struct CompiledPatternBranch { + Node *compiled_pattern; + BlockNode *body; + }; + + Vector<CompiledPatternBranch> compiled_pattern_branches; + }; struct ControlFlowNode : public Node { enum CFType { @@ -267,13 +305,16 @@ public: CF_SWITCH, CF_BREAK, CF_CONTINUE, - CF_RETURN + CF_RETURN, + CF_MATCH }; CFType cf_type; Vector<Node*> arguments; BlockNode *body; BlockNode *body_else; + + MatchNode *match; ControlFlowNode *_else; //used for if ControlFlowNode() { type=TYPE_CONTROL_FLOW; cf_type=CF_IF; body=NULL; body_else=NULL;} @@ -452,6 +493,15 @@ private: Node* _reduce_expression(Node *p_node,bool p_to_const=false); Node* _parse_and_reduce_expression(Node *p_parent,bool p_static,bool p_reduce_const=false,bool p_allow_assign=false); + + + + PatternNode *_parse_pattern(bool p_static); + void _parse_pattern_block(BlockNode *p_block, Vector<PatternBranchNode*> &p_branches, bool p_static); + void _transform_match_statment(BlockNode *p_block, MatchNode *p_match_statement); + void _generate_pattern(PatternNode *p_pattern, Node *p_node_to_match, Node *&p_resulting_node, Map<StringName, Node*> &p_bindings); + + void _parse_block(BlockNode *p_block,bool p_static); void _parse_extends(ClassNode *p_class); void _parse_class(ClassNode *p_class); diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index 0b81780b0..4e72bc39a 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -27,7 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "gd_script.h" -#include "globals.h" +#include "global_config.h" #include "global_constants.h" #include "gd_compiler.h" #include "os/file_access.h" @@ -63,7 +63,7 @@ bool GDNativeClass::_get(const StringName& p_name,Variant &r_ret) const { void GDNativeClass::_bind_methods() { - ClassDB::bind_method(_MD("new"),&GDNativeClass::_new); + ClassDB::bind_method(D_METHOD("new"),&GDNativeClass::_new); } @@ -160,6 +160,8 @@ Variant GDScript::_new(const Variant** p_args,int p_argcount,Variant::CallError& _baseptr=_baseptr->_base; } + ERR_FAIL_COND_V(_baseptr->native.is_null(), Variant()); + if (_baseptr->native.ptr()) { owner=_baseptr->native->instance(); } else { @@ -356,9 +358,11 @@ bool GDScript::get_property_default_value(const StringName& p_property, Variant #ifdef TOOLS_ENABLED - //for (const Map<StringName,Variant>::Element *I=member_default_values.front();I;I=I->next()) { - // print_line("\t"+String(String(I->key())+":"+String(I->get()))); - //} + /* + for (const Map<StringName,Variant>::Element *I=member_default_values.front();I;I=I->next()) { + print_line("\t"+String(String(I->key())+":"+String(I->get()))); + } + */ const Map<StringName,Variant>::Element *E=member_default_values_cache.find(p_property); if (E) { r_value=E->get(); @@ -537,7 +541,7 @@ bool GDScript::_update_exports() { } } - members_cache.clear();; + members_cache.clear(); member_default_values_cache.clear(); for(int i=0;i<c->variables.size();i++) { @@ -785,7 +789,7 @@ void GDScript::_bind_methods() { ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"new",&GDScript::_new,MethodInfo(Variant::OBJECT,"new")); - ClassDB::bind_method(_MD("get_as_byte_code"),&GDScript::get_as_byte_code); + ClassDB::bind_method(D_METHOD("get_as_byte_code"),&GDScript::get_as_byte_code); } @@ -1513,6 +1517,8 @@ void GDScriptLanguage::init() { } _add_global(StaticCString::create("PI"),Math_PI); + _add_global(StaticCString::create("INF"),Math_INF); + _add_global(StaticCString::create("NAN"),Math_NAN); //populate native classes @@ -1860,7 +1866,7 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script>& p_script,bool p_sof void GDScriptLanguage::frame() { - // print_line("calls: "+itos(calls)); + //print_line("calls: "+itos(calls)); calls=0; #ifdef DEBUG_ENABLED @@ -1905,6 +1911,8 @@ void GDScriptLanguage::get_reserved_words(List<String> *p_words) const { "bool", "null", "PI", + "INF", + "NAN", "self", "true", // functions @@ -1934,6 +1942,7 @@ void GDScriptLanguage::get_reserved_words(List<String> *p_words) const { "for", "pass", "return", + "match", "while", "remote", "sync", @@ -2066,7 +2075,7 @@ bool ResourceFormatLoaderGDScript::handles_type(const String& p_type) const { String ResourceFormatLoaderGDScript::get_resource_type(const String &p_path) const { - String el = p_path.extension().to_lower(); + String el = p_path.get_extension().to_lower(); if (el=="gd" || el=="gdc" || el=="gde") return "GDScript"; return ""; diff --git a/modules/gdscript/gd_script.h b/modules/gdscript/gd_script.h index 960b06f3f..4d3baa5bc 100644 --- a/modules/gdscript/gd_script.h +++ b/modules/gdscript/gd_script.h @@ -139,7 +139,7 @@ protected: void _get_property_list(List<PropertyInfo> *p_properties) const; Variant call(const StringName& p_method,const Variant** p_args,int p_argcount,Variant::CallError &r_error); -// void call_multilevel(const StringName& p_method,const Variant** p_args,int p_argcount); + //void call_multilevel(const StringName& p_method,const Variant** p_args,int p_argcount); static void _bind_methods(); public: diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gd_tokenizer.cpp index 30ac98829..54b9624e8 100644 --- a/modules/gdscript/gd_tokenizer.cpp +++ b/modules/gdscript/gd_tokenizer.cpp @@ -85,6 +85,7 @@ const char* GDTokenizer::token_names[TK_MAX]={ "continue", "pass", "return", +"match", "func", "class", "extends", @@ -118,6 +119,9 @@ const char* GDTokenizer::token_names[TK_MAX]={ "':'", "'\\n'", "PI", +"_", +"INF", +"NAN", "Error", "EOF", "Cursor"}; @@ -513,9 +517,11 @@ void GDTokenizerText::_advance() { if (GETCHAR(1)=='=') { _make_token(TK_OP_ASSIGN_ADD); INCPOS(1); - //} else if (GETCHAR(1)=='+') { - // _make_token(TK_OP_PLUS_PLUS); - // INCPOS(1); + /* + } else if (GETCHAR(1)=='+') { + _make_token(TK_OP_PLUS_PLUS); + INCPOS(1); + */ } else { _make_token(TK_OP_ADD); } @@ -526,9 +532,11 @@ void GDTokenizerText::_advance() { if (GETCHAR(1)=='=') { _make_token(TK_OP_ASSIGN_SUB); INCPOS(1); - //} else if (GETCHAR(1)=='-') { - // _make_token(TK_OP_MINUS_MINUS); - // INCPOS(1); + /* + } else if (GETCHAR(1)=='-') { + _make_token(TK_OP_MINUS_MINUS); + INCPOS(1); + */ } else { _make_token(TK_OP_SUB); } @@ -890,9 +898,13 @@ void GDTokenizerText::_advance() { {TK_CF_BREAK,"break"}, {TK_CF_CONTINUE,"continue"}, {TK_CF_RETURN,"return"}, + {TK_CF_MATCH, "match"}, {TK_CF_PASS,"pass"}, {TK_SELF,"self"}, {TK_CONST_PI,"PI"}, + {TK_WILDCARD,"_"}, + {TK_CONST_INF,"INF"}, + {TK_CONST_NAN,"NAN"}, {TK_ERROR,NULL} }; @@ -1161,7 +1173,7 @@ Vector<uint8_t> GDTokenizerBuffer::parse_code_string(const String& p_code) { Map<StringName,int> identifier_map; - HashMap<Variant,int,VariantHasher> constant_map; + HashMap<Variant,int,VariantHasher,VariantComparator> constant_map; Map<uint32_t,int> line_map; Vector<uint32_t> token_array; diff --git a/modules/gdscript/gd_tokenizer.h b/modules/gdscript/gd_tokenizer.h index 18e5547d3..1e9eda794 100644 --- a/modules/gdscript/gd_tokenizer.h +++ b/modules/gdscript/gd_tokenizer.h @@ -92,6 +92,7 @@ public: TK_CF_CONTINUE, TK_CF_PASS, TK_CF_RETURN, + TK_CF_MATCH, TK_PR_FUNCTION, TK_PR_CLASS, TK_PR_EXTENDS, @@ -126,6 +127,9 @@ public: TK_DOLLAR, TK_NEWLINE, TK_CONST_PI, + TK_WILDCARD, + TK_CONST_INF, + TK_CONST_NAN, TK_ERROR, TK_EOF, TK_CURSOR, //used for code completion diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp index 11bdf783f..db47ee43c 100644 --- a/modules/gdscript/register_types.cpp +++ b/modules/gdscript/register_types.cpp @@ -38,7 +38,7 @@ GDScriptLanguage *script_language_gd=NULL; ResourceFormatLoaderGDScript *resource_loader_gd=NULL; ResourceFormatSaverGDScript *resource_saver_gd=NULL; - +#if 0 #ifdef TOOLS_ENABLED #include "tools/editor/editor_import_export.h" @@ -100,7 +100,7 @@ public: if (err==OK) { fae->store_buffer(file.ptr(),file.size()); - p_path=p_path.basename()+".gde"; + p_path=p_path.get_basename()+".gde"; } memdelete(fae); @@ -111,7 +111,7 @@ public: } else { - p_path=p_path.basename()+".gdc"; + p_path=p_path.get_basename()+".gdc"; return file; } } @@ -135,7 +135,7 @@ static void register_editor_plugin() { #endif - +#endif void register_gdscript_types() { ClassDB::register_class<GDScript>(); @@ -148,11 +148,12 @@ void register_gdscript_types() { ResourceLoader::add_resource_format_loader(resource_loader_gd); resource_saver_gd=memnew( ResourceFormatSaverGDScript ); ResourceSaver::add_resource_format_saver(resource_saver_gd); - +#if 0 #ifdef TOOLS_ENABLED EditorNode::add_init_callback(register_editor_plugin); #endif +#endif } void unregister_gdscript_types() { diff --git a/modules/gridmap/config.py b/modules/gridmap/config.py index 1ab13c4ae..5698a3729 100644 --- a/modules/gridmap/config.py +++ b/modules/gridmap/config.py @@ -1,8 +1,7 @@ def can_build(platform): - # FIXME: Disabled temporary for gles3 implementation - return False + return True def configure(env): diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index b5fa55846..d4fb174bf 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -31,7 +31,7 @@ #include "scene/resources/surface_tool.h" #include "message_queue.h" #include "scene/3d/light.h" -#include "scene/3d/baked_light_instance.h" + #include "io/marshalls.h" #include "scene/scene_string_names.h" #include "os/os.h" @@ -41,31 +41,27 @@ bool GridMap::_set(const StringName& p_name, const Variant& p_value) { String name=p_name; - if (name=="theme/theme") { + if (name=="theme") { set_theme(p_value); - } else if (name=="cell/size") { + } else if (name=="cell_size") { set_cell_size(p_value); - } else if (name=="cell/octant_size") { + } else if (name=="cell_octant_size") { set_octant_size(p_value); - } else if (name=="cell/center_x") { + } else if (name=="cell_center_x") { set_center_x(p_value); - } else if (name=="cell/center_y") { + } else if (name=="cell_center_y") { set_center_y(p_value); - } else if (name=="cell/center_z") { + } else if (name=="cell_center_z") { set_center_z(p_value); - } else if (name=="cell/scale") { + } else if (name=="cell_scale") { set_cell_scale(p_value); - } else if (name=="lighting/bake") { - set_use_baked_light(p_value); - } else if (name=="theme/bake") { - set_bake(p_value); /* } else if (name=="cells") { PoolVector<int> cells = p_value; int amount=cells.size(); PoolVector<int>::Read r = cells.read(); ERR_FAIL_COND_V(amount&1,false); // not even - cell_map.clear();; + cell_map.clear(); for(int i=0;i<amount/3;i++) { @@ -81,16 +77,13 @@ bool GridMap::_set(const StringName& p_name, const Variant& p_value) { Dictionary d = p_value; - Dictionary baked; - if (d.has("baked")) - baked=d["baked"]; if (d.has("cells")) { PoolVector<int> cells = d["cells"]; int amount=cells.size(); PoolVector<int>::Read r = cells.read(); ERR_FAIL_COND_V(amount%3,false); // not even - cell_map.clear();; + cell_map.clear(); for(int i=0;i<amount/3;i++) { IndexKey ik; @@ -101,33 +94,7 @@ bool GridMap::_set(const StringName& p_name, const Variant& p_value) { } } - baked_lock=baked.size()!=0; _recreate_octant_data(); - baked_lock=false; - if (!baked.empty()) { - List<Variant> kl; - baked.get_key_list(&kl); - for (List<Variant>::Element *E=kl.front();E;E=E->next()) { - - Plane ikv = E->get(); - Ref<Mesh> b=baked[ikv]; - ERR_CONTINUE(!b.is_valid()); - OctantKey ok; - ok.x=ikv.normal.x; - ok.y=ikv.normal.y; - ok.z=ikv.normal.z; - ok.area=ikv.d; - - ERR_CONTINUE(!octant_map.has(ok)); - - Octant &g = *octant_map[ok]; - - g.baked=b; - g.bake_instance=VS::get_singleton()->instance_create();; - VS::get_singleton()->instance_set_base(g.bake_instance,g.baked->get_rid()); - VS::get_singleton()->instance_geometry_set_baked_light(g.bake_instance,baked_light_instance?baked_light_instance->get_baked_light_instance():RID()); - } - } } else if (name.begins_with("areas/")) { @@ -161,24 +128,20 @@ bool GridMap::_get(const StringName& p_name,Variant &r_ret) const { String name=p_name; - if (name=="theme/theme") { + if (name=="theme") { r_ret= get_theme(); - } else if (name=="cell/size") { + } else if (name=="cell_size") { r_ret= get_cell_size(); - } else if (name=="cell/octant_size") { + } else if (name=="cell_octant_size") { r_ret= get_octant_size(); - } else if (name=="cell/center_x") { + } else if (name=="cell_center_x") { r_ret= get_center_x(); - } else if (name=="cell/center_y") { + } else if (name=="cell_center_y") { r_ret= get_center_y(); - } else if (name=="cell/center_z") { + } else if (name=="cell_center_z") { r_ret= get_center_z(); - } else if (name=="cell/scale") { + } else if (name=="cell_scale") { r_ret= cell_scale; - } else if (name=="lighting/bake") { - r_ret=is_using_baked_light(); - } else if (name=="theme/bake") { - r_ret= bake; } else if (name=="data") { Dictionary d; @@ -197,22 +160,7 @@ bool GridMap::_get(const StringName& p_name,Variant &r_ret) const { d["cells"]=cells; - Dictionary baked; - for(Map<OctantKey,Octant*>::Element *E=octant_map.front();E;E=E->next()) { - - Octant &g=*E->get(); - - if (g.baked.is_valid()) { - - baked[Plane(E->key().x,E->key().y,E->key().z,E->key().area)]=g.baked; - } - - - } - if (baked.size()) { - d["baked"]=baked; - } r_ret= d; } else if (name.begins_with("areas/")) { @@ -237,15 +185,14 @@ bool GridMap::_get(const StringName& p_name,Variant &r_ret) const { void GridMap::_get_property_list( List<PropertyInfo> *p_list) const { - p_list->push_back( PropertyInfo( Variant::OBJECT, "theme/theme", PROPERTY_HINT_RESOURCE_TYPE, "MeshLibrary")); - p_list->push_back( PropertyInfo( Variant::BOOL, "theme/bake")); - p_list->push_back( PropertyInfo( Variant::BOOL, "lighting/bake")); - p_list->push_back( PropertyInfo( Variant::REAL, "cell/size",PROPERTY_HINT_RANGE,"0.01,16384,0.01") ); - p_list->push_back( PropertyInfo( Variant::INT, "cell/octant_size",PROPERTY_HINT_RANGE,"1,1024,1") ); - p_list->push_back( PropertyInfo( Variant::BOOL, "cell/center_x") ); - p_list->push_back( PropertyInfo( Variant::BOOL, "cell/center_y") ); - p_list->push_back( PropertyInfo( Variant::BOOL, "cell/center_z") ); - p_list->push_back( PropertyInfo( Variant::REAL, "cell/scale") ); + p_list->push_back( PropertyInfo( Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "MeshLibrary")); + p_list->push_back( PropertyInfo( Variant::NIL, "Cell", PROPERTY_HINT_NONE,"cell_",PROPERTY_USAGE_GROUP)); + p_list->push_back( PropertyInfo( Variant::REAL, "cell_size",PROPERTY_HINT_RANGE,"0.01,16384,0.01") ); + p_list->push_back( PropertyInfo( Variant::INT, "cell_octant_size",PROPERTY_HINT_RANGE,"1,1024,1") ); + p_list->push_back( PropertyInfo( Variant::BOOL, "cell_center_x") ); + p_list->push_back( PropertyInfo( Variant::BOOL, "cell_center_y") ); + p_list->push_back( PropertyInfo( Variant::BOOL, "cell_center_z") ); + p_list->push_back( PropertyInfo( Variant::REAL, "cell_scale") ); p_list->push_back( PropertyInfo( Variant::DICTIONARY, "data", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_STORAGE) ); @@ -380,17 +327,6 @@ void GridMap::set_cell_item(int p_x,int p_y,int p_z, int p_item,int p_rot){ g.items.erase(prev_item); } - - if (g.items.empty() || !baked_lock) { - //unbake just in case - if (g.baked.is_valid()) { - VS::get_singleton()->free(g.bake_instance); - g.bake_instance=RID(); - g.baked=Ref<Mesh>(); - } - - - } if (g.items.empty()) { PhysicsServer::get_singleton()->free(g.static_body); @@ -454,24 +390,12 @@ void GridMap::set_cell_item(int p_x,int p_y,int p_z, int p_item,int p_rot){ ii.navmesh=theme->get_item_navmesh(p_item); } ii.multimesh = Ref<MultiMesh>( memnew( MultiMesh ) ); + ii.multimesh->set_color_format(MultiMesh::COLOR_NONE); + ii.multimesh->set_transform_format(MultiMesh::TRANSFORM_3D); ii.multimesh->set_mesh(ii.mesh); ii.multimesh_instance = VS::get_singleton()->instance_create(); VS::get_singleton()->instance_set_base(ii.multimesh_instance,ii.multimesh->get_rid()); - VS::get_singleton()->instance_geometry_set_baked_light(ii.multimesh_instance,baked_light_instance?baked_light_instance->get_baked_light_instance():RID()); - if (!baked_lock) { - - //unbake just in case - if (g.bake_instance.is_valid()) - VS::get_singleton()->free(g.bake_instance); - g.baked=Ref<Mesh>(); - if (is_inside_world()) { - VS::get_singleton()->instance_set_scenario(ii.multimesh_instance,get_world()->get_scenario()); - if (ok.area) { - VS::get_singleton()->instance_set_room( ii.multimesh_instance,area_map[ok.area]->instance); - } - } - } g.items[p_item]=ii; } @@ -585,27 +509,14 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) { VS::get_singleton()->instance_set_room(g.collision_debug_instance,area_map[p_key.area]->instance); } } - if (g.baked.is_valid()) { + for(Map<int,Octant::ItemInstances>::Element *E=g.items.front();E;E=E->next()) { - Transform xf = get_global_transform(); - xf.translate(_octant_get_offset(p_key)); + VS::get_singleton()->instance_set_scenario(E->get().multimesh_instance,get_world()->get_scenario()); + VS::get_singleton()->instance_set_transform(E->get().multimesh_instance,get_global_transform()); + //print_line("INSTANCEPOS: "+get_global_transform()); - VS::get_singleton()->instance_set_transform(g.bake_instance,xf); - VS::get_singleton()->instance_set_scenario(g.bake_instance,get_world()->get_scenario()); if (area_map.has(p_key.area)) { - VS::get_singleton()->instance_set_room(g.bake_instance,area_map[p_key.area]->instance); - - } - } else { - for(Map<int,Octant::ItemInstances>::Element *E=g.items.front();E;E=E->next()) { - - VS::get_singleton()->instance_set_scenario(E->get().multimesh_instance,get_world()->get_scenario()); - VS::get_singleton()->instance_set_transform(E->get().multimesh_instance,get_global_transform()); - //print_line("INSTANCEPOS: "+get_global_transform()); - - if (area_map.has(p_key.area)) { - VS::get_singleton()->instance_set_room(E->get().multimesh_instance,area_map[p_key.area]->instance); - } + VS::get_singleton()->instance_set_room(E->get().multimesh_instance,area_map[p_key.area]->instance); } } } @@ -621,17 +532,10 @@ void GridMap::_octant_transform(const OctantKey &p_key) { VS::get_singleton()->instance_set_transform(g.collision_debug_instance,get_global_transform()); } - if (g.baked.is_valid()) { - - Transform xf = get_global_transform(); - xf.origin+=_octant_get_offset(p_key); - VS::get_singleton()->instance_set_transform(g.bake_instance,xf); - } else { - for(Map<int,Octant::ItemInstances>::Element *E=g.items.front();E;E=E->next()) { + for(Map<int,Octant::ItemInstances>::Element *E=g.items.front();E;E=E->next()) { - VS::get_singleton()->instance_set_transform(E->get().multimesh_instance,get_global_transform()); - //print_line("UPDATEPOS: "+get_global_transform()); - } + VS::get_singleton()->instance_set_transform(E->get().multimesh_instance,get_global_transform()); + //print_line("UPDATEPOS: "+get_global_transform()); } } @@ -711,7 +615,7 @@ void GridMap::_octant_update(const OctantKey &p_key) { ii.multimesh->set_instance_transform(idx,xform); //ii.multimesh->set_instance_transform(idx,Transform() ); - ii.multimesh->set_instance_color(idx,Color(1,1,1,1)); + //ii.multimesh->set_instance_color(idx,Color(1,1,1,1)); //print_line("MMINST: "+xform); @@ -731,7 +635,7 @@ void GridMap::_octant_update(const OctantKey &p_key) { ii.shape->add_vertices_to_array(col_debug,xform); } - // print_line("PHIS x: "+xform); + //print_line("PHIS x: "+xform); } // add the item's navmesh at given xform to GridMap's Navigation ancestor @@ -748,7 +652,7 @@ void GridMap::_octant_update(const OctantKey &p_key) { idx++; } - ii.multimesh->set_aabb(aabb); + //ii.multimesh->set_aabb(aabb); } @@ -760,7 +664,7 @@ void GridMap::_octant_update(const OctantKey &p_key) { arr.resize(VS::ARRAY_MAX); arr[VS::ARRAY_VERTEX]=col_debug; - VS::get_singleton()->mesh_add_surface(g.collision_debug,VS::PRIMITIVE_LINES,arr); + VS::get_singleton()->mesh_add_surface_from_arrays(g.collision_debug,VS::PRIMITIVE_LINES,arr); SceneTree *st=SceneTree::get_singleton(); if (st) { VS::get_singleton()->mesh_surface_set_material( g.collision_debug, 0,st->get_debug_collision_material()->get_rid() ); @@ -780,13 +684,6 @@ void GridMap::_octant_exit_world(const OctantKey &p_key) { PhysicsServer::get_singleton()->body_set_space(g.static_body,RID()); - if (g.baked.is_valid()) { - - VS::get_singleton()->instance_set_room(g.bake_instance,RID()); - VS::get_singleton()->instance_set_scenario(g.bake_instance,RID()); - - } - if (g.collision_debug_instance.is_valid()) { VS::get_singleton()->instance_set_room(g.collision_debug_instance,RID()); @@ -796,200 +693,12 @@ void GridMap::_octant_exit_world(const OctantKey &p_key) { for(Map<int,Octant::ItemInstances>::Element *E=g.items.front();E;E=E->next()) { VS::get_singleton()->instance_set_scenario(E->get().multimesh_instance,RID()); - // VS::get_singleton()->instance_set_transform(E->get().multimesh_instance,get_global_transform()); + //VS::get_singleton()->instance_set_transform(E->get().multimesh_instance,get_global_transform()); VS::get_singleton()->instance_set_room(E->get().multimesh_instance,RID()); } } -void GridMap::_octant_clear_baked(const OctantKey &p_key) { - - - ERR_FAIL_COND(!octant_map.has(p_key)); - Octant&g = *octant_map[p_key]; - - if (!g.baked.is_valid()) - return; - - VS::get_singleton()->free(g.bake_instance); - g.bake_instance=RID(); - g.baked=Ref<Mesh>(); - - if (is_inside_tree()) - _octant_enter_world(p_key); - g.dirty=true; - _queue_dirty_map(); -} - -void GridMap::_octant_bake(const OctantKey &p_key, const Ref<TriangleMesh>& p_tmesh,const Vector<BakeLight> &p_lights,List<Vector3> *p_prebake) { - - - ERR_FAIL_COND(!octant_map.has(p_key)); - Octant&g = *octant_map[p_key]; - - Ref<TriangleMesh> tm=p_tmesh; - if (!p_prebake && is_inside_world()) - _octant_exit_world(p_key); - - Map< Ref<Material>, Ref<SurfaceTool> > surfaces; - Vector3 ofs(cell_size*0.5*int(center_x),cell_size*0.5*int(center_y),cell_size*0.5*int(center_z)); - Vector3 octant_ofs=_octant_get_offset(p_key); - - for(Map<int,Octant::ItemInstances>::Element *E=g.items.front();E;E=E->next()) { - - Octant::ItemInstances &ii=E->get(); - - if (ii.mesh.is_null()) - continue; - - for(Set<IndexKey>::Element *F=ii.cells.front();F;F=F->next()) { - - IndexKey ik=F->get(); - Map<IndexKey,Cell>::Element *C=cell_map.find(ik); - ERR_CONTINUE(!C); - Vector3 cellpos = Vector3(ik.x,ik.y,ik.z ); - - Transform xform; - xform.basis.set_orthogonal_index(C->get().rot); - xform.set_origin( cellpos*cell_size+ofs); - if (!p_prebake) - xform.origin-=octant_ofs; - - - for(int i=0;i<ii.mesh->get_surface_count();i++) { - - if (p_prebake) { - - if (ii.mesh->surface_get_primitive_type(i)!=Mesh::PRIMITIVE_TRIANGLES) - continue; - Array a = ii.mesh->surface_get_arrays(i); - PoolVector<Vector3> av=a[VS::ARRAY_VERTEX]; - int avs = av.size(); - PoolVector<Vector3>::Read vr = av.read(); - - PoolVector<int> ai=a[VS::ARRAY_INDEX]; - int ais=ai.size(); - if (ais) { - - PoolVector<int>::Read ir=ai.read(); - for(int j=0;j<ais;j++) { - - p_prebake->push_back(xform.xform(vr[ir[j]])); - //print_line("V SET: "+xform.xform(vr[ir[j]])); - } - - } else { - - for(int j=0;j<avs;j++) { - - p_prebake->push_back(xform.xform(vr[j])); - } - } - - } else { - - Ref<Material> m = ii.mesh->surface_get_material(i); - - Map< Ref<Material>, Ref<SurfaceTool> >::Element *S=surfaces.find(m); - - if (!S) { - - S=surfaces.insert(m,Ref<SurfaceTool>( memnew( SurfaceTool ))); - } - - Ref<SurfaceTool> st = S->get(); - List<SurfaceTool::Vertex>::Element *V=st->get_vertex_array().back(); - st->append_from(ii.mesh,i,xform); - st->set_material(m); - - - if (tm.is_valid()) { - - if (V) - V=V->next(); - else - V=st->get_vertex_array().front();; - int lc = p_lights.size(); - const BakeLight* bl = p_lights.ptr(); - float ofs = cell_size*0.02; - - - for(;V;V=V->next()) { - - SurfaceTool::Vertex &v=V->get(); - - Vector3 vertex = v.vertex + octant_ofs; - //print_line("V GET: "+vertex); - Vector3 normal = tm->get_area_normal( Rect3( Vector3(-ofs,-ofs,-ofs)+vertex,Vector3(ofs,ofs,ofs)*2.0)); - if (normal==Vector3()) { - print_line("couldn't find for vertex: "+vertex); - } - ERR_CONTINUE( normal== Vector3()); - - float max_l=1.0; - float max_dist=1.0; - - if (lc) { - - for(int j=0;j<lc;j++) { - const BakeLight &l=bl[j]; - switch(l.type) { - case VS::LIGHT_DIRECTIONAL: { - - Vector3 ray_from=vertex + normal *ofs; - Vector3 ray_to=l.dir*5000; - Vector3 n; - Vector3 p; - if (tm->intersect_segment(ray_from,ray_to,p,n)) { - - float dist = 1.0-l.param[VS::LIGHT_PARAM_SHADOW_DARKENING]; - if (dist<=max_dist) { - max_dist=dist; - max_l=1.0-dist; - } - } - } break; - } - - } - } - - v.color=Color(max_l,max_l,max_l,1.0); - - } - - st->add_to_format(VS::ARRAY_FORMAT_COLOR); - if (m.is_valid()) { - Ref<FixedSpatialMaterial> fm = m; - if (fm.is_valid()) - fm->set_fixed_flag(FixedSpatialMaterial::FLAG_USE_COLOR_ARRAY,true); - } - } - } - } - } - } - - if (p_prebake) - return; - - g.baked = Ref<Mesh>( memnew( Mesh )); - - for(Map< Ref<Material>, Ref<SurfaceTool> >::Element *E=surfaces.front();E;E=E->next()) { - - Ref<SurfaceTool> st = E->get(); - st->commit(g.baked); - } - - g.bake_instance = VS::get_singleton()->instance_create(); - VS::get_singleton()->instance_set_base(g.bake_instance,g.baked->get_rid()); - - if (is_inside_world()) - _octant_enter_world(p_key); - - g.dirty=true; - _queue_dirty_map(); -} void GridMap::_notification(int p_what) { @@ -1001,8 +710,8 @@ void GridMap::_notification(int p_what) { _update_area_instances(); for(Map<OctantKey,Octant*>::Element *E=octant_map.front();E;E=E->next()) { -// IndexKey ik; -// ik.key = E->key().indexkey; + //IndexKey ik; + //ik.key = E->key().indexkey; _octant_enter_world(E->key()); _octant_update(E->key()); } @@ -1011,10 +720,6 @@ void GridMap::_notification(int p_what) { last_transform=get_global_transform(); - if (use_baked_light) { - - _find_baked_light(); - } } break; case NOTIFICATION_TRANSFORM_CHANGED: { @@ -1036,15 +741,6 @@ void GridMap::_notification(int p_what) { _octant_exit_world(E->key()); } - if (use_baked_light) { - - if (baked_light_instance) { - baked_light_instance->disconnect(SceneStringNames::get_singleton()->baked_light_changed,this,SceneStringNames::get_singleton()->_baked_light_changed); - baked_light_instance=NULL; - } - _baked_light_changed(); - - } //_queue_dirty_map(MAP_DIRTY_INSTANCES|MAP_DIRTY_TRANSFORMS); //_update_dirty_map_callback(); @@ -1122,9 +818,6 @@ void GridMap::_clear_internal(bool p_keep_areas) { VS::get_singleton()->free(F->get().multimesh_instance); } - //unbake just in case - if (E->get()->bake_instance.is_valid()) - VS::get_singleton()->free(E->get()->bake_instance); if (E->get()->collision_debug.is_valid()) VS::get_singleton()->free(E->get()->collision_debug); @@ -1185,60 +878,48 @@ void GridMap::_update_dirty_map_callback() { void GridMap::_bind_methods() { - ClassDB::bind_method(_MD("set_theme","theme:MeshLibrary"),&GridMap::set_theme); - ClassDB::bind_method(_MD("get_theme:MeshLibrary"),&GridMap::get_theme); - - ClassDB::bind_method(_MD("set_bake","enable"),&GridMap::set_bake); - ClassDB::bind_method(_MD("is_baking_enabled"),&GridMap::is_baking_enabled); - - ClassDB::bind_method(_MD("set_cell_size","size"),&GridMap::set_cell_size); - ClassDB::bind_method(_MD("get_cell_size"),&GridMap::get_cell_size); + ClassDB::bind_method(D_METHOD("set_theme","theme:MeshLibrary"),&GridMap::set_theme); + ClassDB::bind_method(D_METHOD("get_theme:MeshLibrary"),&GridMap::get_theme); - ClassDB::bind_method(_MD("set_octant_size","size"),&GridMap::set_octant_size); - ClassDB::bind_method(_MD("get_octant_size"),&GridMap::get_octant_size); + ClassDB::bind_method(D_METHOD("set_cell_size","size"),&GridMap::set_cell_size); + ClassDB::bind_method(D_METHOD("get_cell_size"),&GridMap::get_cell_size); - ClassDB::bind_method(_MD("set_cell_item","x","y","z","item","orientation"),&GridMap::set_cell_item,DEFVAL(0)); - ClassDB::bind_method(_MD("get_cell_item","x","y","z"),&GridMap::get_cell_item); - ClassDB::bind_method(_MD("get_cell_item_orientation","x","y","z"),&GridMap::get_cell_item_orientation); + ClassDB::bind_method(D_METHOD("set_octant_size","size"),&GridMap::set_octant_size); + ClassDB::bind_method(D_METHOD("get_octant_size"),&GridMap::get_octant_size); -// ClassDB::bind_method(_MD("_recreate_octants"),&GridMap::_recreate_octants); - ClassDB::bind_method(_MD("_update_dirty_map_callback"),&GridMap::_update_dirty_map_callback); - ClassDB::bind_method(_MD("resource_changed","resource"),&GridMap::resource_changed); + ClassDB::bind_method(D_METHOD("set_cell_item","x","y","z","item","orientation"),&GridMap::set_cell_item,DEFVAL(0)); + ClassDB::bind_method(D_METHOD("get_cell_item","x","y","z"),&GridMap::get_cell_item); + ClassDB::bind_method(D_METHOD("get_cell_item_orientation","x","y","z"),&GridMap::get_cell_item_orientation); - ClassDB::bind_method(_MD("set_center_x","enable"),&GridMap::set_center_x); - ClassDB::bind_method(_MD("get_center_x"),&GridMap::get_center_x); - ClassDB::bind_method(_MD("set_center_y","enable"),&GridMap::set_center_y); - ClassDB::bind_method(_MD("get_center_y"),&GridMap::get_center_y); - ClassDB::bind_method(_MD("set_center_z","enable"),&GridMap::set_center_z); - ClassDB::bind_method(_MD("get_center_z"),&GridMap::get_center_z); + //ClassDB::bind_method(D_METHOD("_recreate_octants"),&GridMap::_recreate_octants); + ClassDB::bind_method(D_METHOD("_update_dirty_map_callback"),&GridMap::_update_dirty_map_callback); + ClassDB::bind_method(D_METHOD("resource_changed","resource"),&GridMap::resource_changed); - ClassDB::bind_method(_MD("set_clip","enabled","clipabove","floor","axis"),&GridMap::set_clip,DEFVAL(true),DEFVAL(0),DEFVAL(Vector3::AXIS_X)); + ClassDB::bind_method(D_METHOD("set_center_x","enable"),&GridMap::set_center_x); + ClassDB::bind_method(D_METHOD("get_center_x"),&GridMap::get_center_x); + ClassDB::bind_method(D_METHOD("set_center_y","enable"),&GridMap::set_center_y); + ClassDB::bind_method(D_METHOD("get_center_y"),&GridMap::get_center_y); + ClassDB::bind_method(D_METHOD("set_center_z","enable"),&GridMap::set_center_z); + ClassDB::bind_method(D_METHOD("get_center_z"),&GridMap::get_center_z); - ClassDB::bind_method(_MD("create_area","id","area"),&GridMap::create_area); - ClassDB::bind_method(_MD("area_get_bounds","area","bounds"),&GridMap::area_get_bounds); - ClassDB::bind_method(_MD("area_set_exterior_portal","area","enable"),&GridMap::area_set_exterior_portal); - ClassDB::bind_method(_MD("area_set_name","area","name"),&GridMap::area_set_name); - ClassDB::bind_method(_MD("area_get_name","area"),&GridMap::area_get_name); - ClassDB::bind_method(_MD("area_is_exterior_portal","area"),&GridMap::area_is_exterior_portal); - ClassDB::bind_method(_MD("area_set_portal_disable_distance","area","distance"),&GridMap::area_set_portal_disable_distance); - ClassDB::bind_method(_MD("area_get_portal_disable_distance","area"),&GridMap::area_get_portal_disable_distance); - ClassDB::bind_method(_MD("area_set_portal_disable_color","area","color"),&GridMap::area_set_portal_disable_color); - ClassDB::bind_method(_MD("area_get_portal_disable_color","area"),&GridMap::area_get_portal_disable_color); - ClassDB::bind_method(_MD("erase_area","area"),&GridMap::erase_area); - ClassDB::bind_method(_MD("get_unused_area_id","area"),&GridMap::get_unused_area_id); - ClassDB::bind_method(_MD("bake_geometry"),&GridMap::bake_geometry); + ClassDB::bind_method(D_METHOD("set_clip","enabled","clipabove","floor","axis"),&GridMap::set_clip,DEFVAL(true),DEFVAL(0),DEFVAL(Vector3::AXIS_X)); - ClassDB::bind_method(_MD("_baked_light_changed"),&GridMap::_baked_light_changed); - ClassDB::bind_method(_MD("set_use_baked_light","use"),&GridMap::set_use_baked_light); - ClassDB::bind_method(_MD("is_using_baked_light","use"),&GridMap::is_using_baked_light); + ClassDB::bind_method(D_METHOD("create_area","id","area"),&GridMap::create_area); + ClassDB::bind_method(D_METHOD("area_get_bounds","area","bounds"),&GridMap::area_get_bounds); + ClassDB::bind_method(D_METHOD("area_set_exterior_portal","area","enable"),&GridMap::area_set_exterior_portal); + ClassDB::bind_method(D_METHOD("area_set_name","area","name"),&GridMap::area_set_name); + ClassDB::bind_method(D_METHOD("area_get_name","area"),&GridMap::area_get_name); + ClassDB::bind_method(D_METHOD("area_is_exterior_portal","area"),&GridMap::area_is_exterior_portal); + ClassDB::bind_method(D_METHOD("area_set_portal_disable_distance","area","distance"),&GridMap::area_set_portal_disable_distance); + ClassDB::bind_method(D_METHOD("area_get_portal_disable_distance","area"),&GridMap::area_get_portal_disable_distance); + ClassDB::bind_method(D_METHOD("area_set_portal_disable_color","area","color"),&GridMap::area_set_portal_disable_color); + ClassDB::bind_method(D_METHOD("area_get_portal_disable_color","area"),&GridMap::area_get_portal_disable_color); + ClassDB::bind_method(D_METHOD("erase_area","area"),&GridMap::erase_area); + ClassDB::bind_method(D_METHOD("get_unused_area_id","area"),&GridMap::get_unused_area_id); - ClassDB::bind_method(_MD("_get_baked_light_meshes"),&GridMap::_get_baked_light_meshes); + ClassDB::bind_method(D_METHOD("clear"),&GridMap::clear); - - - ClassDB::set_method_flags("GridMap","bake_geometry",METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR); - - ClassDB::bind_method(_MD("clear"),&GridMap::clear); + ClassDB::bind_method(D_METHOD("get_meshes"),&GridMap::get_meshes); BIND_CONSTANT( INVALID_CELL_ITEM ); @@ -1622,23 +1303,6 @@ int GridMap::get_unused_area_id() const { return area_map.back()->key()+1; } - -void GridMap::set_bake(bool p_bake) { - - bake=p_bake; - if (bake==false) { - for(Map<OctantKey,Octant*>::Element *E=octant_map.front();E;E=E->next()) { - - _octant_clear_baked(E->key()); - } - } -} - -bool GridMap::is_baking_enabled() const { - - return bake; -} - void GridMap::set_cell_scale(float p_scale) { cell_scale=p_scale; @@ -1652,98 +1316,8 @@ float GridMap::get_cell_scale() const{ -void GridMap::bake_geometry() { - - //used to compute vertex occlusion - Ref<TriangleMesh> tmesh; - Vector<BakeLight> lights; - - if (true) { - - List<Vector3> vertices; - - for(Map<OctantKey,Octant*>::Element *E=octant_map.front();E;E=E->next()) { - _octant_bake(E->key(),tmesh,lights,&vertices); - - } - - PoolVector<Vector3> vv; - vv.fill_with(vertices); - //print_line("TOTAL VERTICES: "+itos(vv.size())); - tmesh = Ref<TriangleMesh>( memnew( TriangleMesh )); - tmesh->create(vv); - - - for(int i=0;i<get_child_count();i++) { - - if (get_child(i)->cast_to<Light>()) { - Light *l = get_child(i)->cast_to<Light>(); - BakeLight bl; - for(int i=0;i<Light::PARAM_MAX;i++) { - bl.param[i]=l->get_parameter(Light::Parameter(i)); - } - Transform t=l->get_global_transform(); - bl.pos=t.origin; - bl.dir=t.basis.get_axis(2); - bl.type=l->get_light_type(); - lights.push_back(bl); - - } - } - } - - int idx=0; - for(Map<OctantKey,Octant*>::Element *E=octant_map.front();E;E=E->next()) { - if (E->get()->baked.is_valid()) - _octant_clear_baked(E->key()); - - _octant_bake(E->key(),tmesh,lights); - print_line("baking "+itos(idx)+"/"+itos(octant_map.size())); - idx++; - } - -} - -void GridMap::_baked_light_changed() { - -// if (!baked_light_instance) -// VS::get_singleton()->instance_geometry_set_baked_light(get_instance(),RID()); -// else -// VS::get_singleton()->instance_geometry_set_baked_light(get_instance(),baked_light_instance->get_baked_light_instance()); - for(Map<OctantKey,Octant*>::Element *E=octant_map.front();E;E=E->next()) { - - for(Map<int,Octant::ItemInstances>::Element *F=E->get()->items.front();F;F=F->next()) { - - VS::get_singleton()->instance_geometry_set_baked_light(F->get().multimesh_instance,baked_light_instance?baked_light_instance->get_baked_light_instance():RID()); - } - - } - -} -void GridMap::_find_baked_light() { - - Node *n=get_parent(); - while(n) { - - BakedLightInstance *bl=n->cast_to<BakedLightInstance>(); - if (bl) { - - baked_light_instance=bl; - baked_light_instance->connect(SceneStringNames::get_singleton()->baked_light_changed,this,SceneStringNames::get_singleton()->_baked_light_changed); - _baked_light_changed(); - - return; - } - - n=n->get_parent(); - } - - _baked_light_changed(); -} - - -Array GridMap::_get_baked_light_meshes() { +Array GridMap::get_meshes() { if (theme.is_null()) return Array(); @@ -1781,31 +1355,6 @@ Array GridMap::_get_baked_light_meshes() { return meshes; } -void GridMap::set_use_baked_light(bool p_use) { - - if (use_baked_light==p_use) - return; - - use_baked_light=p_use; - - if (is_inside_world()) { - if (!p_use) { - if (baked_light_instance) { - baked_light_instance->disconnect(SceneStringNames::get_singleton()->baked_light_changed,this,SceneStringNames::get_singleton()->_baked_light_changed); - baked_light_instance=NULL; - } - _baked_light_changed(); - } else { - _find_baked_light(); - } - } - -} - -bool GridMap::is_using_baked_light() const{ - - return use_baked_light; -} @@ -1823,14 +1372,11 @@ GridMap::GridMap() { clip_floor=0; clip_axis=Vector3::AXIS_Z; clip_above=true; - baked_lock=false; - bake=false; cell_scale=1.0; - baked_light_instance=NULL; - use_baked_light=false; navigation = NULL; + set_notify_transform(true); } diff --git a/modules/gridmap/grid_map.h b/modules/gridmap/grid_map.h index 04d140cdc..5d4133383 100644 --- a/modules/gridmap/grid_map.h +++ b/modules/gridmap/grid_map.h @@ -103,8 +103,6 @@ class GridMap : public Spatial { Ref<NavigationMesh> navmesh; }; - Ref<Mesh> baked; - RID bake_instance; RID collision_debug; RID collision_debug_instance; @@ -140,14 +138,12 @@ class GridMap : public Spatial { float cell_size; int octant_size; bool center_x,center_y,center_z; - bool bake; float cell_scale; Navigation *navigation; bool clip; bool clip_above; int clip_floor; - bool baked_lock; Vector3::Axis clip_axis; @@ -205,9 +201,7 @@ class GridMap : public Spatial { void _octant_exit_world(const OctantKey &p_key); void _octant_update(const OctantKey &p_key); void _octant_transform(const OctantKey &p_key); - void _octant_clear_baked(const OctantKey &p_key); void _octant_clear_navmesh(const GridMap::OctantKey&); - void _octant_bake(const OctantKey &p_key,const Ref<TriangleMesh>& p_tmesh=RES(),const Vector<BakeLight> &p_lights=Vector<BakeLight>(),List<Vector3> *r_prebake=NULL); bool awaiting_update; void _queue_dirty_map(); @@ -221,14 +215,6 @@ class GridMap : public Spatial { void _clear_internal(bool p_keep_areas=false); - BakedLightInstance *baked_light_instance; - bool use_baked_light; - void _find_baked_light(); - void _baked_light_changed(); - - - Array _get_baked_light_meshes(); - protected: bool _set(const StringName& p_name, const Variant& p_value); @@ -285,13 +271,11 @@ public: void set_cell_scale(float p_scale); float get_cell_scale() const; - void set_bake(bool p_bake); - bool is_baking_enabled() const; - void bake_geometry(); - void set_use_baked_light(bool p_use); - bool is_using_baked_light() const; + Array get_meshes(); + + void clear(); GridMap(); diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index 109f6338d..263036005 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -249,7 +249,7 @@ void GridMapEditor::_update_cursor_transform() { if (cursor_instance.is_valid()) { VisualServer::get_singleton()->instance_set_transform(cursor_instance,cursor_transform); - VisualServer::get_singleton()->instance_geometry_set_flag(cursor_instance,VS::INSTANCE_FLAG_VISIBLE,cursor_visible); + VisualServer::get_singleton()->instance_set_visible(cursor_instance,cursor_visible); } } @@ -852,11 +852,11 @@ void GridMapEditor::edit(GridMap *p_gridmap) { if (!node) { set_process(false); for(int i=0;i<3;i++) { - VisualServer::get_singleton()->instance_geometry_set_flag(grid_instance[i],VS::INSTANCE_FLAG_VISIBLE,false); + VisualServer::get_singleton()->instance_set_visible(grid_instance[i],false); } - VisualServer::get_singleton()->instance_geometry_set_flag(cursor_instance, VS::INSTANCE_FLAG_VISIBLE,false); + VisualServer::get_singleton()->instance_set_visible(cursor_instance,false); _clear_areas(); @@ -884,13 +884,11 @@ void GridMapEditor::edit(GridMap *p_gridmap) { { //update grids - indicator_mat = VisualServer::get_singleton()->fixed_material_create(); - VisualServer::get_singleton()->material_set_flag( indicator_mat, VisualServer::MATERIAL_FLAG_UNSHADED, true ); - VisualServer::get_singleton()->material_set_flag( indicator_mat, VisualServer::MATERIAL_FLAG_ONTOP, false ); - - VisualServer::get_singleton()->fixed_material_set_param(indicator_mat,VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE,Color(0.8,0.5,0.1)); - VisualServer::get_singleton()->fixed_material_set_flag( indicator_mat, VisualServer::FIXED_MATERIAL_FLAG_USE_ALPHA, true ); - VisualServer::get_singleton()->fixed_material_set_flag( indicator_mat, VisualServer::FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY, true ); + indicator_mat.instance(); + indicator_mat->set_flag(FixedSpatialMaterial::FLAG_UNSHADED,true); + indicator_mat->set_flag(FixedSpatialMaterial::FLAG_SRGB_VERTEX_COLOR,true); + indicator_mat->set_flag(FixedSpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR,true); + indicator_mat->set_albedo(Color(0.8,0.5,0.1)); Vector<Vector3> grid_points[3]; @@ -903,7 +901,7 @@ void GridMapEditor::edit(GridMap *p_gridmap) { Vector3 axis; axis[i]=1; Vector3 axis_n1; - axis_n1[(i+1)%3]=cell_size[(i+1)%3];; + axis_n1[(i+1)%3]=cell_size[(i+1)%3]; Vector3 axis_n2; axis_n2[(i+2)%3]=cell_size[(i+2)%3]; @@ -937,8 +935,8 @@ void GridMapEditor::edit(GridMap *p_gridmap) { d.resize(VS::ARRAY_MAX); d[VS::ARRAY_VERTEX]=grid_points[i]; d[VS::ARRAY_COLOR]=grid_colors[i]; - VisualServer::get_singleton()->mesh_add_surface(grid[i],VisualServer::PRIMITIVE_LINES,d); - VisualServer::get_singleton()->mesh_surface_set_material(grid[i],0,indicator_mat); + VisualServer::get_singleton()->mesh_add_surface_from_arrays(grid[i],VisualServer::PRIMITIVE_LINES,d); + VisualServer::get_singleton()->mesh_surface_set_material(grid[i],0,indicator_mat->get_rid()); } @@ -976,7 +974,7 @@ void GridMapEditor::update_grid() { for(int i=0;i<3;i++) { - VisualServer::get_singleton()->instance_geometry_set_flag(grid_instance[i],VS::INSTANCE_FLAG_VISIBLE,i==edit_axis); + VisualServer::get_singleton()->instance_set_visible(grid_instance[i],i==edit_axis); } @@ -1103,7 +1101,7 @@ void GridMapEditor::_update_areas_display() { if (!node) { return; } - +#if 0 _clear_areas(); List<int> areas; node->get_area_list(&areas); @@ -1118,6 +1116,8 @@ void GridMapEditor::_update_areas_display() { color=Color(1,1,1,0.2); else color.set_hsv(Math::fmod(area*0.37,1),Math::fmod(area*0.75,1),1.0,0.2); + + RID material = VisualServer::get_singleton()->fixed_material_create(); VisualServer::get_singleton()->fixed_material_set_param( material, VS::FIXED_MATERIAL_PARAM_DIFFUSE,color ); VisualServer::get_singleton()->fixed_material_set_param( material, VS::FIXED_MATERIAL_PARAM_EMISSION,0.5 ); @@ -1149,7 +1149,7 @@ void GridMapEditor::_update_areas_display() { this->areas.push_back(ad); } - +#endif } void GridMapEditor::_edit_mode_changed(int p_what) { @@ -1189,7 +1189,7 @@ void GridMapEditor::_bind_methods() { ClassDB::bind_method("_area_selected",&GridMapEditor::_area_selected); ClassDB::bind_method("_floor_changed",&GridMapEditor::_floor_changed); - ClassDB::bind_method(_MD("_set_display_mode","mode"), &GridMapEditor::_set_display_mode); + ClassDB::bind_method(D_METHOD("_set_display_mode","mode"), &GridMapEditor::_set_display_mode); } @@ -1274,8 +1274,8 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { edit_mode = memnew(OptionButton); edit_mode->set_area_as_parent_rect(); - edit_mode->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_BEGIN,24);; - edit_mode->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,14);; + edit_mode->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_BEGIN,24); + edit_mode->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,14); edit_mode->add_item("Tiles"); edit_mode->add_item("Areas"); hb->add_child(edit_mode); @@ -1295,7 +1295,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { hb->add_child(mode_list); mode_list->connect("pressed", this, "_set_display_mode", varray(DISPLAY_LIST)); - EDITOR_DEF("editors/grid_map/preview_size",64) + EDITOR_DEF("editors/grid_map/preview_size",64); display_mode = DISPLAY_THUMBNAIL; selected_area=-1; @@ -1387,52 +1387,36 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { Array d; d.resize(VS::ARRAY_MAX); - inner_mat = VisualServer::get_singleton()->fixed_material_create(); - VisualServer::get_singleton()->fixed_material_set_param(inner_mat,VS::FIXED_MATERIAL_PARAM_DIFFUSE,Color(0.7,0.7,1.0,0.3)); - VisualServer::get_singleton()->material_set_flag(inner_mat,VS::MATERIAL_FLAG_ONTOP,true); - VisualServer::get_singleton()->material_set_flag(inner_mat,VS::MATERIAL_FLAG_UNSHADED,true); - VisualServer::get_singleton()->fixed_material_set_flag( inner_mat, VisualServer::FIXED_MATERIAL_FLAG_USE_ALPHA, true ); + inner_mat.instance(); + inner_mat->set_albedo(Color(0.7,0.7,1.0,0.3)); + inner_mat->set_flag(FixedSpatialMaterial::FLAG_ONTOP,true); + inner_mat->set_flag(FixedSpatialMaterial::FLAG_UNSHADED,true); + inner_mat->set_feature(FixedSpatialMaterial::FEATURE_TRANSPARENT,true); d[VS::ARRAY_VERTEX]=triangles; - VisualServer::get_singleton()->mesh_add_surface(selection_mesh,VS::PRIMITIVE_TRIANGLES,d); - VisualServer::get_singleton()->mesh_surface_set_material(selection_mesh,0,inner_mat); + VisualServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh,VS::PRIMITIVE_TRIANGLES,d); + VisualServer::get_singleton()->mesh_surface_set_material(selection_mesh,0,inner_mat->get_rid()); - outer_mat = VisualServer::get_singleton()->fixed_material_create(); - VisualServer::get_singleton()->fixed_material_set_param(outer_mat,VS::FIXED_MATERIAL_PARAM_DIFFUSE,Color(0.7,0.7,1.0,0.8)); - VisualServer::get_singleton()->material_set_line_width(outer_mat,3.0); - VisualServer::get_singleton()->material_set_flag(outer_mat,VS::MATERIAL_FLAG_ONTOP,true); - VisualServer::get_singleton()->material_set_flag(outer_mat,VS::MATERIAL_FLAG_UNSHADED,true); - VisualServer::get_singleton()->fixed_material_set_flag( outer_mat, VisualServer::FIXED_MATERIAL_FLAG_USE_ALPHA, true ); + outer_mat.instance(); + outer_mat->set_albedo(Color(0.7,0.7,1.0,0.3)); + outer_mat->set_flag(FixedSpatialMaterial::FLAG_ONTOP,true); + outer_mat->set_flag(FixedSpatialMaterial::FLAG_UNSHADED,true); + outer_mat->set_line_width(3.0); + outer_mat->set_feature(FixedSpatialMaterial::FEATURE_TRANSPARENT,true); d[VS::ARRAY_VERTEX]=lines; - VisualServer::get_singleton()->mesh_add_surface(selection_mesh,VS::PRIMITIVE_LINES,d); - VisualServer::get_singleton()->mesh_surface_set_material(selection_mesh,1,outer_mat); - - - inner_mat_dup = VisualServer::get_singleton()->fixed_material_create(); - VisualServer::get_singleton()->fixed_material_set_param(inner_mat_dup,VS::FIXED_MATERIAL_PARAM_DIFFUSE,Color(1.0,0.7,0.7,0.3)); - VisualServer::get_singleton()->material_set_flag(inner_mat_dup,VS::MATERIAL_FLAG_ONTOP,true); - VisualServer::get_singleton()->material_set_flag(inner_mat_dup,VS::MATERIAL_FLAG_UNSHADED,true); - VisualServer::get_singleton()->fixed_material_set_flag( inner_mat_dup, VisualServer::FIXED_MATERIAL_FLAG_USE_ALPHA, true ); - + VisualServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh,VS::PRIMITIVE_LINES,d); + VisualServer::get_singleton()->mesh_surface_set_material(selection_mesh,1,outer_mat->get_rid()); d[VS::ARRAY_VERTEX]=triangles; - VisualServer::get_singleton()->mesh_add_surface(duplicate_mesh,VS::PRIMITIVE_TRIANGLES,d); - VisualServer::get_singleton()->mesh_surface_set_material(duplicate_mesh,0,inner_mat_dup); - - outer_mat_dup = VisualServer::get_singleton()->fixed_material_create(); - VisualServer::get_singleton()->fixed_material_set_param(outer_mat_dup,VS::FIXED_MATERIAL_PARAM_DIFFUSE,Color(1.0,0.7,0.7,0.8)); - VisualServer::get_singleton()->material_set_line_width(outer_mat_dup,3.0); - VisualServer::get_singleton()->material_set_flag(outer_mat_dup,VS::MATERIAL_FLAG_ONTOP,true); - VisualServer::get_singleton()->material_set_flag(outer_mat_dup,VS::MATERIAL_FLAG_UNSHADED,true); - VisualServer::get_singleton()->fixed_material_set_flag( outer_mat_dup, VisualServer::FIXED_MATERIAL_FLAG_USE_ALPHA, true ); - + VisualServer::get_singleton()->mesh_add_surface_from_arrays(duplicate_mesh,VS::PRIMITIVE_TRIANGLES,d); + VisualServer::get_singleton()->mesh_surface_set_material(duplicate_mesh,0,inner_mat->get_rid()); d[VS::ARRAY_VERTEX]=lines; - VisualServer::get_singleton()->mesh_add_surface(duplicate_mesh,VS::PRIMITIVE_LINES,d); - VisualServer::get_singleton()->mesh_surface_set_material(duplicate_mesh,1,outer_mat_dup); + VisualServer::get_singleton()->mesh_add_surface_from_arrays(duplicate_mesh,VS::PRIMITIVE_LINES,d); + VisualServer::get_singleton()->mesh_surface_set_material(duplicate_mesh,1,outer_mat->get_rid()); } @@ -1452,14 +1436,10 @@ GridMapEditor::~GridMapEditor() { VisualServer::get_singleton()->free(grid[i]); if (grid_instance[i].is_valid()) VisualServer::get_singleton()->free(grid_instance[i]); - if (cursor_instance) + if (cursor_instance.is_valid()) VisualServer::get_singleton()->free(cursor_instance); } - VisualServer::get_singleton()->free(inner_mat); - VisualServer::get_singleton()->free(outer_mat); - VisualServer::get_singleton()->free(inner_mat_dup); - VisualServer::get_singleton()->free(outer_mat_dup); VisualServer::get_singleton()->free(selection_mesh); if (selection_instance.is_valid()) diff --git a/modules/gridmap/grid_map_editor_plugin.h b/modules/gridmap/grid_map_editor_plugin.h index 2c0ff99dc..66ec5dc4b 100644 --- a/modules/gridmap/grid_map_editor_plugin.h +++ b/modules/gridmap/grid_map_editor_plugin.h @@ -112,12 +112,9 @@ class GridMapEditor : public VBoxContainer { RID duplicate_mesh; RID duplicate_instance; - RID indicator_mat; - - RID inner_mat; - RID outer_mat; - RID inner_mat_dup; - RID outer_mat_dup; + Ref<FixedSpatialMaterial> indicator_mat; + Ref<FixedSpatialMaterial> inner_mat; + Ref<FixedSpatialMaterial> outer_mat; bool updating; diff --git a/modules/gridmap/register_types.cpp b/modules/gridmap/register_types.cpp index b4a0d3b0b..9cd70a0f9 100644 --- a/modules/gridmap/register_types.cpp +++ b/modules/gridmap/register_types.cpp @@ -28,7 +28,7 @@ /*************************************************************************/ #include "register_types.h" #ifndef _3D_DISABLED -#include "object_type_db.h" +#include "class_db.h" #include "grid_map.h" #include "grid_map_editor_plugin.h" #endif diff --git a/modules/ogg/config.py b/modules/ogg/config.py index fb920482f..ef5daca05 100644 --- a/modules/ogg/config.py +++ b/modules/ogg/config.py @@ -1,6 +1,7 @@ def can_build(platform): - return True +# return True + return False def configure(env): diff --git a/modules/openssl/stream_peer_openssl.cpp b/modules/openssl/stream_peer_openssl.cpp index 140ea1b9e..43a1f610d 100644 --- a/modules/openssl/stream_peer_openssl.cpp +++ b/modules/openssl/stream_peer_openssl.cpp @@ -35,8 +35,8 @@ bool StreamPeerOpenSSL::_match_host_name(const char *name, const char *hostname) { return Tool_Curl_cert_hostcheck(name,hostname)==CURL_HOST_MATCH; -// print_line("MATCH: "+String(name)+" vs "+String(hostname)); -// return true; + //print_line("MATCH: "+String(name)+" vs "+String(hostname)); + //return true; } Error StreamPeerOpenSSL::_match_common_name(const char *hostname, const X509 *server_cert) { @@ -293,10 +293,10 @@ BIO_METHOD StreamPeerOpenSSL::_bio_method = { _bio_destroy }; -Error StreamPeerOpenSSL::connect(Ref<StreamPeer> p_base, bool p_validate_certs, const String& p_for_hostname) { +Error StreamPeerOpenSSL::connect_to_stream(Ref<StreamPeer> p_base, bool p_validate_certs, const String& p_for_hostname) { if (connected) - disconnect(); + disconnect_from_stream(); hostname=p_for_hostname; @@ -415,7 +415,7 @@ Error StreamPeerOpenSSL::connect(Ref<StreamPeer> p_base, bool p_validate_certs, return OK; } -Error StreamPeerOpenSSL::accept(Ref<StreamPeer> p_base) { +Error StreamPeerOpenSSL::accept_stream(Ref<StreamPeer> p_base) { return ERR_UNAVAILABLE; @@ -451,7 +451,7 @@ Error StreamPeerOpenSSL::put_data(const uint8_t* p_data,int p_bytes) { int ret = SSL_write(ssl,p_data,p_bytes); if (ret<=0) { _print_error(ret); - disconnect(); + disconnect_from_stream(); return ERR_CONNECTION_ERROR; } p_data+=ret; @@ -486,7 +486,7 @@ Error StreamPeerOpenSSL::get_data(uint8_t* p_buffer, int p_bytes){ int ret = SSL_read(ssl,p_buffer,p_bytes); if (ret<=0) { _print_error(ret); - disconnect(); + disconnect_from_stream(); return ERR_CONNECTION_ERROR; } p_buffer+=ret; @@ -529,7 +529,7 @@ StreamPeerOpenSSL::StreamPeerOpenSSL() { flags=0; } -void StreamPeerOpenSSL::disconnect() { +void StreamPeerOpenSSL::disconnect_from_stream() { if (!connected) return; @@ -552,7 +552,7 @@ StreamPeerOpenSSL::Status StreamPeerOpenSSL::get_status() const { StreamPeerOpenSSL::~StreamPeerOpenSSL() { - disconnect(); + disconnect_from_stream(); } StreamPeerSSL* StreamPeerOpenSSL::_create_func() { diff --git a/modules/openssl/stream_peer_openssl.h b/modules/openssl/stream_peer_openssl.h index d79fb97ff..84ae03fe0 100644 --- a/modules/openssl/stream_peer_openssl.h +++ b/modules/openssl/stream_peer_openssl.h @@ -31,7 +31,7 @@ #include <stdio.h> // If you don't know what this is for stop reading now. #include "io/stream_peer_ssl.h" -#include "globals.h" +#include "global_config.h" #include "os/file_access.h" #include "curl_hostcheck.h" @@ -85,11 +85,11 @@ protected: public: - virtual Error accept(Ref<StreamPeer> p_base); - virtual Error connect(Ref<StreamPeer> p_base,bool p_validate_certs=false,const String& p_for_hostname=String()); + virtual Error accept_stream(Ref<StreamPeer> p_base); + virtual Error connect_to_stream(Ref<StreamPeer> p_base,bool p_validate_certs=false,const String& p_for_hostname=String()); virtual Status get_status() const; - virtual void disconnect(); + virtual void disconnect_from_stream(); virtual Error put_data(const uint8_t* p_data,int p_bytes); virtual Error put_partial_data(const uint8_t* p_data,int p_bytes, int &r_sent); diff --git a/modules/opus/audio_stream_opus.cpp b/modules/opus/audio_stream_opus.cpp index f438dde68..4a6b2e224 100644 --- a/modules/opus/audio_stream_opus.cpp +++ b/modules/opus/audio_stream_opus.cpp @@ -366,7 +366,7 @@ void ResourceFormatLoaderAudioStreamOpus::get_recognized_extensions(List<String> } String ResourceFormatLoaderAudioStreamOpus::get_resource_type(const String &p_path) const { - if (p_path.extension().to_lower()=="opus") + if (p_path.get_extension().to_lower()=="opus") return "AudioStreamOpus"; return ""; } diff --git a/modules/opus/config.py b/modules/opus/config.py index fb920482f..ef5daca05 100644 --- a/modules/opus/config.py +++ b/modules/opus/config.py @@ -1,6 +1,7 @@ def can_build(platform): - return True +# return True + return False def configure(env): diff --git a/modules/pbm/bitmap_loader_pbm.cpp b/modules/pbm/bitmap_loader_pbm.cpp index 6caaf1033..ab0805a6b 100644 --- a/modules/pbm/bitmap_loader_pbm.cpp +++ b/modules/pbm/bitmap_loader_pbm.cpp @@ -244,7 +244,7 @@ bool ResourceFormatPBM::handles_type(const String& p_type) const { } String ResourceFormatPBM::get_resource_type(const String &p_path) const { - if (p_path.extension().to_lower()=="pbm") + if (p_path.get_extension().to_lower()=="pbm") return "BitMap"; return ""; } diff --git a/modules/pvr/texture_loader_pvr.cpp b/modules/pvr/texture_loader_pvr.cpp index 9f8db98e0..9805675f2 100644 --- a/modules/pvr/texture_loader_pvr.cpp +++ b/modules/pvr/texture_loader_pvr.cpp @@ -185,7 +185,7 @@ bool ResourceFormatPVR::handles_type(const String& p_type) const { String ResourceFormatPVR::get_resource_type(const String &p_path) const { - if (p_path.extension().to_lower()=="pvr") + if (p_path.get_extension().to_lower()=="pvr") return "Texture"; return ""; } @@ -464,16 +464,19 @@ static void get_modulation_value(int x, int y, const int p_2bit, const int p_mod if(((x^y)&1)==0) mod_val = rep_vals0[p_modulation[y][x]]; else if(p_modulation_modes[y][x] == 1) { - mod_val = (rep_vals0[p_modulation[y-1][x]] + - rep_vals0[p_modulation[y+1][x]] + - rep_vals0[p_modulation[y][x-1]] + - rep_vals0[p_modulation[y][x+1]] + 2) / 4; + mod_val = ( + rep_vals0[p_modulation[y-1][x]] + + rep_vals0[p_modulation[y+1][x]] + + rep_vals0[p_modulation[y][x-1]] + + rep_vals0[p_modulation[y][x+1]] + 2) / 4; } else if(p_modulation_modes[y][x] == 2) { - mod_val = (rep_vals0[p_modulation[y][x-1]] + - rep_vals0[p_modulation[y][x+1]] + 1) / 2; + mod_val = ( + rep_vals0[p_modulation[y][x-1]] + + rep_vals0[p_modulation[y][x+1]] + 1) / 2; } else { - mod_val = (rep_vals0[p_modulation[y-1][x]] + - rep_vals0[p_modulation[y+1][x]] + 1) / 2; + mod_val = ( + rep_vals0[p_modulation[y-1][x]] + + rep_vals0[p_modulation[y+1][x]] + 1) / 2; } } else { mod_val = rep_vals1[p_modulation[y][x]]; @@ -615,11 +618,12 @@ static void decompress_pvrtc(PVRTCBlock *p_comp_img, const int p_2bit, const int for(j = 0; j < 2; j++) { unpack_5554(p_blocks[i][j], colors5554[i][j].Reps); - unpack_modulations(p_blocks[i][j], - p_2bit, - p_modulation, - p_modulation_modes, - p_x, p_y); + unpack_modulations( + p_blocks[i][j], + p_2bit, + p_modulation, + p_modulation_modes, + p_x, p_y); p_x += x_block_size; } @@ -632,19 +636,21 @@ static void decompress_pvrtc(PVRTCBlock *p_comp_img, const int p_2bit, const int } - interpolate_colors(colors5554[0][0].Reps[0], - colors5554[0][1].Reps[0], - colors5554[1][0].Reps[0], - colors5554[1][1].Reps[0], - p_2bit, x, y, - ASig); + interpolate_colors( + colors5554[0][0].Reps[0], + colors5554[0][1].Reps[0], + colors5554[1][0].Reps[0], + colors5554[1][1].Reps[0], + p_2bit, x, y, + ASig); - interpolate_colors(colors5554[0][0].Reps[1], - colors5554[0][1].Reps[1], - colors5554[1][0].Reps[1], - colors5554[1][1].Reps[1], - p_2bit, x, y, - BSig); + interpolate_colors( + colors5554[0][0].Reps[1], + colors5554[0][1].Reps[1], + colors5554[1][0].Reps[1], + colors5554[1][1].Reps[1], + p_2bit, x, y, + BSig); get_modulation_value(x,y, p_2bit, (const int (*)[16])p_modulation, (const int (*)[16])p_modulation_modes, &Mod, &DoPT); @@ -669,9 +675,11 @@ static void decompress_pvrtc(PVRTCBlock *p_comp_img, const int p_2bit, const int static void _pvrtc_decompress(Image* p_img) { -// static void decompress_pvrtc(const void *p_comp_img, const int p_2bit, const int p_width, const int p_height, unsigned char* p_dst) { -// decompress_pvrtc((PVRTCBlock*)p_comp_img,p_2bit,p_width,p_height,1,p_dst); -// } + /* + static void decompress_pvrtc(const void *p_comp_img, const int p_2bit, const int p_width, const int p_height, unsigned char* p_dst) { + decompress_pvrtc((PVRTCBlock*)p_comp_img,p_2bit,p_width,p_height,1,p_dst); + } + */ ERR_FAIL_COND( p_img->get_format()!=Image::FORMAT_PVRTC2 && p_img->get_format()!=Image::FORMAT_PVRTC2A && p_img->get_format()!=Image::FORMAT_PVRTC4 && p_img->get_format()!=Image::FORMAT_PVRTC4A); @@ -687,9 +695,11 @@ static void _pvrtc_decompress(Image* p_img) { decompress_pvrtc((PVRTCBlock*)r.ptr(),_2bit,p_img->get_width(),p_img->get_height(),0,(unsigned char*)w.ptr()); - //for(int i=0;i<newdata.size();i++) { - // print_line(itos(w[i])); - //} + /* + for(int i=0;i<newdata.size();i++) { + print_line(itos(w[i])); + } + */ w=PoolVector<uint8_t>::Write(); r=PoolVector<uint8_t>::Read(); diff --git a/modules/regex/regex.cpp b/modules/regex/regex.cpp index e67040b5a..3d1dd048a 100644 --- a/modules/regex/regex.cpp +++ b/modules/regex/regex.cpp @@ -321,7 +321,7 @@ struct RegExNodeClass : public RegExNode { case Type_lower: return ('a' <= c && c <= 'z'); case Type_print: - return (0x1F < c && c < 0x1F); + return (0x20 < c && c < 0x7f); case Type_punct: return (REGEX_NODE_PUNCT.find(c) >= 0); case Type_space: @@ -1481,27 +1481,27 @@ RegEx::~RegEx() { void RegExMatch::_bind_methods() { - ClassDB::bind_method(_MD("expand","template"),&RegExMatch::expand); - ClassDB::bind_method(_MD("get_group_count"),&RegExMatch::get_group_count); - ClassDB::bind_method(_MD("get_group_array"),&RegExMatch::get_group_array); - ClassDB::bind_method(_MD("get_names"),&RegExMatch::get_names); - ClassDB::bind_method(_MD("get_name_dict"),&RegExMatch::get_name_dict); - ClassDB::bind_method(_MD("get_string","name"),&RegExMatch::get_string, DEFVAL(0)); - ClassDB::bind_method(_MD("get_start","name"),&RegExMatch::get_start, DEFVAL(0)); - ClassDB::bind_method(_MD("get_end","name"),&RegExMatch::get_end, DEFVAL(0)); + ClassDB::bind_method(D_METHOD("expand","template"),&RegExMatch::expand); + ClassDB::bind_method(D_METHOD("get_group_count"),&RegExMatch::get_group_count); + ClassDB::bind_method(D_METHOD("get_group_array"),&RegExMatch::get_group_array); + ClassDB::bind_method(D_METHOD("get_names"),&RegExMatch::get_names); + ClassDB::bind_method(D_METHOD("get_name_dict"),&RegExMatch::get_name_dict); + ClassDB::bind_method(D_METHOD("get_string","name"),&RegExMatch::get_string, DEFVAL(0)); + ClassDB::bind_method(D_METHOD("get_start","name"),&RegExMatch::get_start, DEFVAL(0)); + ClassDB::bind_method(D_METHOD("get_end","name"),&RegExMatch::get_end, DEFVAL(0)); } void RegEx::_bind_methods() { - ClassDB::bind_method(_MD("clear"),&RegEx::clear); - ClassDB::bind_method(_MD("compile","pattern"),&RegEx::compile); - ClassDB::bind_method(_MD("search","text","start","end"),&RegEx::search, DEFVAL(0), DEFVAL(-1)); - ClassDB::bind_method(_MD("sub","text","replacement","all","start","end"),&RegEx::sub, DEFVAL(false), DEFVAL(0), DEFVAL(-1)); - ClassDB::bind_method(_MD("is_valid"),&RegEx::is_valid); - ClassDB::bind_method(_MD("get_pattern"),&RegEx::get_pattern); - ClassDB::bind_method(_MD("get_group_count"),&RegEx::get_group_count); - ClassDB::bind_method(_MD("get_names"),&RegEx::get_names); + ClassDB::bind_method(D_METHOD("clear"),&RegEx::clear); + ClassDB::bind_method(D_METHOD("compile","pattern"),&RegEx::compile); + ClassDB::bind_method(D_METHOD("search","text","start","end"),&RegEx::search, DEFVAL(0), DEFVAL(-1)); + ClassDB::bind_method(D_METHOD("sub","text","replacement","all","start","end"),&RegEx::sub, DEFVAL(false), DEFVAL(0), DEFVAL(-1)); + ClassDB::bind_method(D_METHOD("is_valid"),&RegEx::is_valid); + ClassDB::bind_method(D_METHOD("get_pattern"),&RegEx::get_pattern); + ClassDB::bind_method(D_METHOD("get_group_count"),&RegEx::get_group_count); + ClassDB::bind_method(D_METHOD("get_names"),&RegEx::get_names); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "pattern"), _SCS("compile"), _SCS("get_pattern")); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "pattern"), "compile", "get_pattern"); } diff --git a/modules/regex/register_types.cpp b/modules/regex/register_types.cpp index d44c7e563..c62a04d80 100644 --- a/modules/regex/register_types.cpp +++ b/modules/regex/register_types.cpp @@ -28,7 +28,7 @@ /*************************************************************************/ #include "register_types.h" -#include "object_type_db.h" +#include "class_db.h" #include "regex.h" void register_regex_types() { diff --git a/modules/squish/image_compress_squish.cpp b/modules/squish/image_compress_squish.cpp index 741065860..28c200596 100644 --- a/modules/squish/image_compress_squish.cpp +++ b/modules/squish/image_compress_squish.cpp @@ -54,20 +54,19 @@ void image_compress_squish(Image *p_image) { if (p_image->get_format()==Image::FORMAT_LA8) { //compressed normalmap - target_format = Image::FORMAT_DXT5; squish_comp|=squish::kDxt5;; + target_format = Image::FORMAT_DXT5; squish_comp|=squish::kDxt5; } else if (p_image->detect_alpha()!=Image::ALPHA_NONE) { - target_format = Image::FORMAT_DXT3; squish_comp|=squish::kDxt3;; + target_format = Image::FORMAT_DXT3; squish_comp|=squish::kDxt3; } else { - target_format = Image::FORMAT_DXT1; shift=1; squish_comp|=squish::kDxt1;; + target_format = Image::FORMAT_DXT1; shift=1; squish_comp|=squish::kDxt1; } p_image->convert(Image::FORMAT_RGBA8); //always expects rgba - int mm_count = p_image->get_mipmap_count(); - PoolVector<uint8_t> data; - int target_size = Image::get_image_data_size(w,h,target_format,mm_count); + int target_size = Image::get_image_data_size(w,h,target_format,p_image->has_mipmaps()?-1:0); + int mm_count = p_image->has_mipmaps() ? Image::get_image_required_mipmaps(w,h,target_format) : 0; data.resize(target_size); PoolVector<uint8_t>::Read rb = p_image->get_data().read(); diff --git a/modules/stb_vorbis/SCsub b/modules/stb_vorbis/SCsub new file mode 100644 index 000000000..897d05961 --- /dev/null +++ b/modules/stb_vorbis/SCsub @@ -0,0 +1,10 @@ +#!/usr/bin/env python + +Import('env') +Import('env_modules') + +# Thirdparty source files + +env_stb_vorbis = env_modules.Clone() + +env_stb_vorbis.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp new file mode 100644 index 000000000..ee7cbeece --- /dev/null +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp @@ -0,0 +1,232 @@ + +#include "audio_stream_ogg_vorbis.h" +#include "thirdparty/stb_vorbis/stb_vorbis.c" +#include "os/file_access.h" + + +void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame* p_buffer,int p_frames) { + + ERR_FAIL_COND(!active); + + int todo=p_frames; + + while(todo) { + + int mixed = stb_vorbis_get_samples_float_interleaved(ogg_stream,2,(float*)p_buffer,todo*2); + todo-=mixed; + + if (todo) { + //end of file! + if (vorbis_stream->loop) { + //loop + seek_pos(0); + loops++; + } else { + for(int i=mixed;i<p_frames;i++) { + p_buffer[i]=AudioFrame(0,0); + } + active=false; + } + } + } + + +} + +float AudioStreamPlaybackOGGVorbis::get_stream_sampling_rate() { + + return vorbis_stream->sample_rate; +} + + +void AudioStreamPlaybackOGGVorbis::start(float p_from_pos) { + + seek_pos(p_from_pos); + active=true; + loops=0; + _begin_resample(); + + +} + +void AudioStreamPlaybackOGGVorbis::stop() { + + active=false; +} +bool AudioStreamPlaybackOGGVorbis::is_playing() const { + + return active; +} + +int AudioStreamPlaybackOGGVorbis::get_loop_count() const { + + return loops; +} + +float AudioStreamPlaybackOGGVorbis::get_pos() const { + + return float(frames_mixed)/vorbis_stream->sample_rate; +} +void AudioStreamPlaybackOGGVorbis::seek_pos(float p_time) { + + if (!active) + return; + + stb_vorbis_seek(ogg_stream, uint32_t(p_time*vorbis_stream->sample_rate)); +} + +float AudioStreamPlaybackOGGVorbis::get_length() const { + + return vorbis_stream->length; +} + +AudioStreamPlaybackOGGVorbis::~AudioStreamPlaybackOGGVorbis() { + if (ogg_alloc.alloc_buffer) { + AudioServer::get_singleton()->audio_data_free(ogg_alloc.alloc_buffer); + stb_vorbis_close(ogg_stream); + } +} + +Ref<AudioStreamPlayback> AudioStreamOGGVorbis::instance_playback() { + + + + Ref<AudioStreamPlaybackOGGVorbis> ovs; + printf("instance at %p, data %p\n",this,data); + + ERR_FAIL_COND_V(data==NULL,ovs); + + ovs.instance(); + ovs->vorbis_stream=Ref<AudioStreamOGGVorbis>(this); + ovs->ogg_alloc.alloc_buffer=(char*)AudioServer::get_singleton()->audio_data_alloc(decode_mem_size); + ovs->ogg_alloc.alloc_buffer_length_in_bytes=decode_mem_size; + ovs->frames_mixed=0; + ovs->active=false; + ovs->loops=0; + int error ; + ovs->ogg_stream = stb_vorbis_open_memory( (const unsigned char*)data, data_len, &error, &ovs->ogg_alloc ); + if (!ovs->ogg_stream) { + + AudioServer::get_singleton()->audio_data_free(ovs->ogg_alloc.alloc_buffer); + ovs->ogg_alloc.alloc_buffer=NULL; + ERR_FAIL_COND_V(!ovs->ogg_stream,Ref<AudioStreamPlaybackOGGVorbis>()); + } + + return ovs; +} + +String AudioStreamOGGVorbis::get_stream_name() const { + + return "";//return stream_name; +} + +void AudioStreamOGGVorbis::set_data(const PoolVector<uint8_t>& p_data) { + + int src_data_len=p_data.size(); +#define MAX_TEST_MEM (1<<20) + + uint32_t alloc_try=1024; + PoolVector<char> alloc_mem; + PoolVector<char>::Write w; + stb_vorbis * ogg_stream=NULL; + stb_vorbis_alloc ogg_alloc; + + while(alloc_try<MAX_TEST_MEM) { + + alloc_mem.resize(alloc_try); + w = alloc_mem.write(); + + ogg_alloc.alloc_buffer=w.ptr(); + ogg_alloc.alloc_buffer_length_in_bytes=alloc_try; + + PoolVector<uint8_t>::Read src_datar = p_data.read(); + + int error; + ogg_stream = stb_vorbis_open_memory( (const unsigned char*)src_datar.ptr(), src_data_len, &error, &ogg_alloc ); + + if (!ogg_stream && error==VORBIS_outofmem) { + w = PoolVector<char>::Write(); + alloc_try*=2; + } else { + + ERR_FAIL_COND(alloc_try==MAX_TEST_MEM); + ERR_FAIL_COND(ogg_stream==NULL); + + stb_vorbis_info info = stb_vorbis_get_info(ogg_stream); + + channels = info.channels; + sample_rate = info.sample_rate; + decode_mem_size = alloc_try; + //does this work? (it's less mem..) + //decode_mem_size = ogg_alloc.alloc_buffer_length_in_bytes + info.setup_memory_required + info.temp_memory_required + info.max_frame_size; + + //print_line("succeded "+itos(ogg_alloc.alloc_buffer_length_in_bytes)+" setup "+itos(info.setup_memory_required)+" setup temp "+itos(info.setup_temp_memory_required)+" temp "+itos(info.temp_memory_required)+" maxframe"+itos(info.max_frame_size)); + + length=stb_vorbis_stream_length_in_seconds(ogg_stream); + stb_vorbis_close(ogg_stream); + + data = AudioServer::get_singleton()->audio_data_alloc(src_data_len,src_datar.ptr()); + data_len=src_data_len; + + break; + } + } + + + printf("create at %p, data %p\n",this,data); + +} + +PoolVector<uint8_t> AudioStreamOGGVorbis::get_data() const { + + PoolVector<uint8_t> vdata; + + if (data_len && data) { + vdata.resize(data_len); + { + PoolVector<uint8_t>::Write w = vdata.write(); + copymem(w.ptr(),data,data_len); + } + + } + + return vdata; +} + +void AudioStreamOGGVorbis::set_loop(bool p_enable) { + loop=p_enable; +} + +bool AudioStreamOGGVorbis::has_loop() const { + + return loop; +} + + +void AudioStreamOGGVorbis::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_data","data"),&AudioStreamOGGVorbis::set_data); + ClassDB::bind_method(D_METHOD("get_data"),&AudioStreamOGGVorbis::get_data); + + ClassDB::bind_method(D_METHOD("set_loop","enable"),&AudioStreamOGGVorbis::set_loop); + ClassDB::bind_method(D_METHOD("has_loop"),&AudioStreamOGGVorbis::has_loop); + + ADD_PROPERTY(PropertyInfo(Variant::POOL_BYTE_ARRAY,"data",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_data","get_data"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL,"loop",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_loop","has_loop"); + +} + +AudioStreamOGGVorbis::AudioStreamOGGVorbis() { + + + data=NULL; + length=0; + sample_rate=1; + channels=1; + decode_mem_size=0; + loop=false; +} + + + + diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.h b/modules/stb_vorbis/audio_stream_ogg_vorbis.h new file mode 100644 index 000000000..21ce23740 --- /dev/null +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.h @@ -0,0 +1,83 @@ +#ifndef AUDIO_STREAM_STB_VORBIS_H +#define AUDIO_STREAM_STB_VORBIS_H + +#include "servers/audio/audio_stream.h" +#include "io/resource_loader.h" + +#define STB_VORBIS_HEADER_ONLY +#include "thirdparty/stb_vorbis/stb_vorbis.c" +#undef STB_VORBIS_HEADER_ONLY + + +class AudioStreamOGGVorbis; + +class AudioStreamPlaybackOGGVorbis : public AudioStreamPlaybackResampled { + + GDCLASS( AudioStreamPlaybackOGGVorbis, AudioStreamPlaybackResampled ) + + stb_vorbis * ogg_stream; + stb_vorbis_alloc ogg_alloc; + uint32_t frames_mixed; + bool active; + int loops; + +friend class AudioStreamOGGVorbis; + + Ref<AudioStreamOGGVorbis> vorbis_stream; +protected: + + virtual void _mix_internal(AudioFrame* p_buffer, int p_frames); + virtual float get_stream_sampling_rate(); + +public: + virtual void start(float p_from_pos=0.0); + virtual void stop(); + virtual bool is_playing() const; + + virtual int get_loop_count() const; //times it looped + + virtual float get_pos() const; + virtual void seek_pos(float p_time); + + virtual float get_length() const; //if supported, otherwise return 0 + + AudioStreamPlaybackOGGVorbis() { } + ~AudioStreamPlaybackOGGVorbis(); +}; + +class AudioStreamOGGVorbis : public AudioStream { + + GDCLASS( AudioStreamOGGVorbis, AudioStream ) + OBJ_SAVE_TYPE( AudioStream ) //children are all saved as AudioStream, so they can be exchanged + RES_BASE_EXTENSION("asogg"); + +friend class AudioStreamPlaybackOGGVorbis; + + void *data; + uint32_t data_len; + + int decode_mem_size; + float sample_rate; + int channels; + float length; + bool loop; +protected: + + static void _bind_methods(); +public: + + void set_loop(bool p_enable); + bool has_loop() const; + + virtual Ref<AudioStreamPlayback> instance_playback(); + virtual String get_stream_name() const; + + void set_data(const PoolVector<uint8_t>& p_data); + PoolVector<uint8_t> get_data() const; + + AudioStreamOGGVorbis(); +}; + + + +#endif diff --git a/modules/chibi/config.py b/modules/stb_vorbis/config.py index fb920482f..fb920482f 100644 --- a/modules/chibi/config.py +++ b/modules/stb_vorbis/config.py diff --git a/modules/chibi/register_types.cpp b/modules/stb_vorbis/register_types.cpp index 1a0c80881..41fbc6fbd 100644 --- a/modules/chibi/register_types.cpp +++ b/modules/stb_vorbis/register_types.cpp @@ -27,15 +27,19 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "register_types.h" +#include "audio_stream_ogg_vorbis.h" +#include "resource_importer_ogg_vorbis.h" -#include "event_stream_chibi.h" +void register_stb_vorbis_types() { -void register_chibi_types() { - - initialize_chibi(); +#ifdef TOOLS_ENABLED + Ref<ResourceImporterOGGVorbis> ogg_import; + ogg_import.instance(); + ResourceFormatImporter::get_singleton()->add_importer(ogg_import); +#endif + ClassDB::register_class<AudioStreamOGGVorbis>(); } -void unregister_chibi_types() { +void unregister_stb_vorbis_types() { - finalize_chibi(); } diff --git a/modules/chibi/register_types.h b/modules/stb_vorbis/register_types.h index 08856c074..2824aa9f0 100644 --- a/modules/chibi/register_types.h +++ b/modules/stb_vorbis/register_types.h @@ -26,5 +26,5 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -void register_chibi_types(); -void unregister_chibi_types(); +void register_stb_vorbis_types(); +void unregister_stb_vorbis_types(); diff --git a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp new file mode 100644 index 000000000..6f90c8587 --- /dev/null +++ b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp @@ -0,0 +1,84 @@ +#include "resource_importer_ogg_vorbis.h" + +#include "io/resource_saver.h" +#include "os/file_access.h" +#include "scene/resources/texture.h" + +String ResourceImporterOGGVorbis::get_importer_name() const { + + return "ogg_vorbis"; +} + +String ResourceImporterOGGVorbis::get_visible_name() const{ + + return "OGGVorbis"; +} +void ResourceImporterOGGVorbis::get_recognized_extensions(List<String> *p_extensions) const{ + + p_extensions->push_back("ogg"); +} + +String ResourceImporterOGGVorbis::get_save_extension() const { + return "asogg"; +} + +String ResourceImporterOGGVorbis::get_resource_type() const{ + + return "AudioStreamOGGVorbis"; +} + +bool ResourceImporterOGGVorbis::get_option_visibility(const String& p_option,const Map<StringName,Variant>& p_options) const { + + return true; +} + +int ResourceImporterOGGVorbis::get_preset_count() const { + return 0; +} +String ResourceImporterOGGVorbis::get_preset_name(int p_idx) const { + + return String(); +} + + +void ResourceImporterOGGVorbis::get_import_options(List<ImportOption> *r_options,int p_preset) const { + + + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"loop"),true)); + +} + + + +Error ResourceImporterOGGVorbis::import(const String& p_source_file, const String& p_save_path, const Map<StringName,Variant>& p_options, List<String>* r_platform_variants, List<String> *r_gen_files) { + + bool loop = p_options["loop"]; + + FileAccess *f = FileAccess::open(p_source_file,FileAccess::READ); + if (!f) { + ERR_FAIL_COND_V(!f,ERR_CANT_OPEN); + } + + size_t len = f->get_len(); + + PoolVector<uint8_t> data; + data.resize(len); + PoolVector<uint8_t>::Write w = data.write(); + + f->get_buffer(w.ptr(),len); + + memdelete(f); + + Ref<AudioStreamOGGVorbis> ogg_stream; + ogg_stream.instance(); + + ogg_stream->set_data(data); + ogg_stream->set_loop(loop); + + return ResourceSaver::save(p_save_path+".asogg",ogg_stream); +} + +ResourceImporterOGGVorbis::ResourceImporterOGGVorbis() +{ + +} diff --git a/modules/stb_vorbis/resource_importer_ogg_vorbis.h b/modules/stb_vorbis/resource_importer_ogg_vorbis.h new file mode 100644 index 000000000..8a3b2d8ec --- /dev/null +++ b/modules/stb_vorbis/resource_importer_ogg_vorbis.h @@ -0,0 +1,28 @@ +#ifndef RESOURCEIMPORTEROGGVORBIS_H +#define RESOURCEIMPORTEROGGVORBIS_H + + +#include "io/resource_import.h" +#include "audio_stream_ogg_vorbis.h" + +class ResourceImporterOGGVorbis : public ResourceImporter { + GDCLASS(ResourceImporterOGGVorbis,ResourceImporter) +public: + virtual String get_importer_name() const; + virtual String get_visible_name() const; + virtual void get_recognized_extensions(List<String> *p_extensions) const; + virtual String get_save_extension() const; + virtual String get_resource_type() const; + + virtual int get_preset_count() const; + virtual String get_preset_name(int p_idx) const; + + virtual void get_import_options(List<ImportOption> *r_options,int p_preset=0) const; + virtual bool get_option_visibility(const String& p_option,const Map<StringName,Variant>& p_options) const; + + virtual Error import(const String& p_source_file,const String& p_save_path,const Map<StringName,Variant>& p_options,List<String>* r_platform_variants,List<String>* r_gen_files=NULL); + + ResourceImporterOGGVorbis(); +}; + +#endif // RESOURCEIMPORTEROGGVORBIS_H diff --git a/modules/theora/config.py b/modules/theora/config.py index fb920482f..8eefe8128 100644 --- a/modules/theora/config.py +++ b/modules/theora/config.py @@ -1,6 +1,7 @@ def can_build(platform): - return True +# return True + return False def configure(env): diff --git a/modules/theora/video_stream_theora.cpp b/modules/theora/video_stream_theora.cpp index b847f17bb..2a7b2707b 100644 --- a/modules/theora/video_stream_theora.cpp +++ b/modules/theora/video_stream_theora.cpp @@ -28,7 +28,7 @@ /*************************************************************************/ #include "video_stream_theora.h" -#include "globals.h" +#include "global_config.h" #include "os/os.h" #include "yuv2rgb.h" @@ -81,6 +81,9 @@ void VideoStreamPlaybackTheora::video_write(void){ th_ycbcr_buffer yuv; th_decode_ycbcr_out(td,yuv); + // FIXME: The way stuff is commented out with `//*/` closing comments + // sounds very fishy... + /* int y_offset, uv_offset; y_offset=(ti.pic_x&~1)+yuv[0].stride*(ti.pic_y&~1); @@ -105,7 +108,7 @@ void VideoStreamPlaybackTheora::video_write(void){ } format = Image::FORMAT_RGBA8; } - // */ + //*/ //* @@ -228,7 +231,7 @@ void VideoStreamPlaybackTheora::video_write(void){ format = Image::FORMAT_YUV_422; }; }; - // */ + //*/ frames_pending = 1; } @@ -598,7 +601,7 @@ void VideoStreamPlaybackTheora::update(float p_delta) { if (vd.granulepos>=0) { - // print_line("wrote: "+itos(audio_frames_wrote)+" gpos: "+itos(vd.granulepos)); + //print_line("wrote: "+itos(audio_frames_wrote)+" gpos: "+itos(vd.granulepos)); } //print_line("mix audio!"); @@ -933,7 +936,7 @@ bool ResourceFormatLoaderVideoStreamTheora::handles_type(const String& p_type) c String ResourceFormatLoaderVideoStreamTheora::get_resource_type(const String &p_path) const { - String exl=p_path.extension().to_lower(); + String exl=p_path.get_extension().to_lower(); if (exl=="ogm" || exl=="ogv") return "VideoStreamTheora"; return ""; diff --git a/modules/theora/yuv2rgb.h b/modules/theora/yuv2rgb.h index 431b47e65..3b81607a6 100644 --- a/modules/theora/yuv2rgb.h +++ b/modules/theora/yuv2rgb.h @@ -3,8 +3,7 @@ #include "typedefs.h" -static const uint32_t tables[256*3] = -{ +static const uint32_t tables[256*3] = { /* y_table */ 0x7FFFFFEDU, 0x7FFFFFEFU, diff --git a/modules/visual_script/register_types.cpp b/modules/visual_script/register_types.cpp index 79bf3d50b..5fe87a495 100644 --- a/modules/visual_script/register_types.cpp +++ b/modules/visual_script/register_types.cpp @@ -82,7 +82,7 @@ void register_visual_script_types() { ClassDB::register_class<VisualScriptFunctionCall>(); ClassDB::register_class<VisualScriptPropertySet>(); ClassDB::register_class<VisualScriptPropertyGet>(); -// ClassDB::register_type<VisualScriptScriptCall>(); + //ClassDB::register_type<VisualScriptScriptCall>(); ClassDB::register_class<VisualScriptEmitSignal>(); ClassDB::register_class<VisualScriptReturn>(); diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index 08796b386..6941ed548 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -2,7 +2,7 @@ #include "visual_script_nodes.h" #include "scene/main/node.h" #include "os/os.h" -#include "globals.h" +#include "global_config.h" @@ -104,13 +104,13 @@ Array VisualScriptNode::_get_default_input_values() const { void VisualScriptNode::_bind_methods() { - ClassDB::bind_method(_MD("get_visual_script:VisualScript"),&VisualScriptNode::get_visual_script); - ClassDB::bind_method(_MD("set_default_input_value","port_idx","value:Variant"),&VisualScriptNode::set_default_input_value); - ClassDB::bind_method(_MD("get_default_input_value:Variant","port_idx"),&VisualScriptNode::get_default_input_value); - ClassDB::bind_method(_MD("_set_default_input_values","values"),&VisualScriptNode::_set_default_input_values); - ClassDB::bind_method(_MD("_get_default_input_values"),&VisualScriptNode::_get_default_input_values); + ClassDB::bind_method(D_METHOD("get_visual_script:VisualScript"),&VisualScriptNode::get_visual_script); + ClassDB::bind_method(D_METHOD("set_default_input_value","port_idx","value:Variant"),&VisualScriptNode::set_default_input_value); + ClassDB::bind_method(D_METHOD("get_default_input_value:Variant","port_idx"),&VisualScriptNode::get_default_input_value); + ClassDB::bind_method(D_METHOD("_set_default_input_values","values"),&VisualScriptNode::_set_default_input_values); + ClassDB::bind_method(D_METHOD("_get_default_input_values"),&VisualScriptNode::_get_default_input_values); - ADD_PROPERTY(PropertyInfo(Variant::ARRAY,"_default_input_values",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_default_input_values"),_SCS("_get_default_input_values")); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY,"_default_input_values",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"_set_default_input_values","_get_default_input_values"); ADD_SIGNAL(MethodInfo("ports_changed")); } @@ -1317,65 +1317,65 @@ void VisualScript::_bind_methods() { - ClassDB::bind_method(_MD("_node_ports_changed"),&VisualScript::_node_ports_changed); + ClassDB::bind_method(D_METHOD("_node_ports_changed"),&VisualScript::_node_ports_changed); - ClassDB::bind_method(_MD("add_function","name"),&VisualScript::add_function); - ClassDB::bind_method(_MD("has_function","name"),&VisualScript::has_function); - ClassDB::bind_method(_MD("remove_function","name"),&VisualScript::remove_function); - ClassDB::bind_method(_MD("rename_function","name","new_name"),&VisualScript::rename_function); - ClassDB::bind_method(_MD("set_function_scroll","ofs"),&VisualScript::set_function_scroll); - ClassDB::bind_method(_MD("get_function_scroll"),&VisualScript::get_function_scroll); + ClassDB::bind_method(D_METHOD("add_function","name"),&VisualScript::add_function); + ClassDB::bind_method(D_METHOD("has_function","name"),&VisualScript::has_function); + ClassDB::bind_method(D_METHOD("remove_function","name"),&VisualScript::remove_function); + ClassDB::bind_method(D_METHOD("rename_function","name","new_name"),&VisualScript::rename_function); + ClassDB::bind_method(D_METHOD("set_function_scroll","ofs"),&VisualScript::set_function_scroll); + ClassDB::bind_method(D_METHOD("get_function_scroll"),&VisualScript::get_function_scroll); - ClassDB::bind_method(_MD("add_node","func","id","node","pos"),&VisualScript::add_node,DEFVAL(Point2())); - ClassDB::bind_method(_MD("remove_node","func","id"),&VisualScript::remove_node); - ClassDB::bind_method(_MD("get_function_node_id","name"),&VisualScript::get_function_node_id); + ClassDB::bind_method(D_METHOD("add_node","func","id","node","pos"),&VisualScript::add_node,DEFVAL(Point2())); + ClassDB::bind_method(D_METHOD("remove_node","func","id"),&VisualScript::remove_node); + ClassDB::bind_method(D_METHOD("get_function_node_id","name"),&VisualScript::get_function_node_id); - ClassDB::bind_method(_MD("get_node","func","id"),&VisualScript::get_node); - ClassDB::bind_method(_MD("has_node","func","id"),&VisualScript::has_node); - ClassDB::bind_method(_MD("set_node_pos","func","id","pos"),&VisualScript::set_node_pos); - ClassDB::bind_method(_MD("get_node_pos","func","id"),&VisualScript::get_node_pos); + ClassDB::bind_method(D_METHOD("get_node","func","id"),&VisualScript::get_node); + ClassDB::bind_method(D_METHOD("has_node","func","id"),&VisualScript::has_node); + ClassDB::bind_method(D_METHOD("set_node_pos","func","id","pos"),&VisualScript::set_node_pos); + ClassDB::bind_method(D_METHOD("get_node_pos","func","id"),&VisualScript::get_node_pos); - ClassDB::bind_method(_MD("sequence_connect","func","from_node","from_output","to_node"),&VisualScript::sequence_connect); - ClassDB::bind_method(_MD("sequence_disconnect","func","from_node","from_output","to_node"),&VisualScript::sequence_disconnect); - ClassDB::bind_method(_MD("has_sequence_connection","func","from_node","from_output","to_node"),&VisualScript::has_sequence_connection); + ClassDB::bind_method(D_METHOD("sequence_connect","func","from_node","from_output","to_node"),&VisualScript::sequence_connect); + ClassDB::bind_method(D_METHOD("sequence_disconnect","func","from_node","from_output","to_node"),&VisualScript::sequence_disconnect); + ClassDB::bind_method(D_METHOD("has_sequence_connection","func","from_node","from_output","to_node"),&VisualScript::has_sequence_connection); - ClassDB::bind_method(_MD("data_connect","func","from_node","from_port","to_node","to_port"),&VisualScript::data_connect); - ClassDB::bind_method(_MD("data_disconnect","func","from_node","from_port","to_node","to_port"),&VisualScript::data_disconnect); - ClassDB::bind_method(_MD("has_data_connection","func","from_node","from_port","to_node","to_port"),&VisualScript::has_data_connection); + ClassDB::bind_method(D_METHOD("data_connect","func","from_node","from_port","to_node","to_port"),&VisualScript::data_connect); + ClassDB::bind_method(D_METHOD("data_disconnect","func","from_node","from_port","to_node","to_port"),&VisualScript::data_disconnect); + ClassDB::bind_method(D_METHOD("has_data_connection","func","from_node","from_port","to_node","to_port"),&VisualScript::has_data_connection); - ClassDB::bind_method(_MD("add_variable","name","default_value","export"),&VisualScript::add_variable,DEFVAL(Variant()),DEFVAL(false)); - ClassDB::bind_method(_MD("has_variable","name"),&VisualScript::has_variable); - ClassDB::bind_method(_MD("remove_variable","name"),&VisualScript::remove_variable); - ClassDB::bind_method(_MD("set_variable_default_value","name","value"),&VisualScript::set_variable_default_value); - ClassDB::bind_method(_MD("get_variable_default_value","name"),&VisualScript::get_variable_default_value); - ClassDB::bind_method(_MD("set_variable_info","name","value"),&VisualScript::_set_variable_info); - ClassDB::bind_method(_MD("get_variable_info","name"),&VisualScript::_get_variable_info); - ClassDB::bind_method(_MD("set_variable_export","name","enable"),&VisualScript::set_variable_export); - ClassDB::bind_method(_MD("get_variable_export","name"),&VisualScript::get_variable_export); - ClassDB::bind_method(_MD("rename_variable","name","new_name"),&VisualScript::rename_variable); + ClassDB::bind_method(D_METHOD("add_variable","name","default_value","export"),&VisualScript::add_variable,DEFVAL(Variant()),DEFVAL(false)); + ClassDB::bind_method(D_METHOD("has_variable","name"),&VisualScript::has_variable); + ClassDB::bind_method(D_METHOD("remove_variable","name"),&VisualScript::remove_variable); + ClassDB::bind_method(D_METHOD("set_variable_default_value","name","value"),&VisualScript::set_variable_default_value); + ClassDB::bind_method(D_METHOD("get_variable_default_value","name"),&VisualScript::get_variable_default_value); + ClassDB::bind_method(D_METHOD("set_variable_info","name","value"),&VisualScript::_set_variable_info); + ClassDB::bind_method(D_METHOD("get_variable_info","name"),&VisualScript::_get_variable_info); + ClassDB::bind_method(D_METHOD("set_variable_export","name","enable"),&VisualScript::set_variable_export); + ClassDB::bind_method(D_METHOD("get_variable_export","name"),&VisualScript::get_variable_export); + ClassDB::bind_method(D_METHOD("rename_variable","name","new_name"),&VisualScript::rename_variable); - ClassDB::bind_method(_MD("add_custom_signal","name"),&VisualScript::add_custom_signal); - ClassDB::bind_method(_MD("has_custom_signal","name"),&VisualScript::has_custom_signal); - ClassDB::bind_method(_MD("custom_signal_add_argument","name","type","argname","index"),&VisualScript::custom_signal_add_argument,DEFVAL(-1)); - ClassDB::bind_method(_MD("custom_signal_set_argument_type","name","argidx","type"),&VisualScript::custom_signal_set_argument_type); - ClassDB::bind_method(_MD("custom_signal_get_argument_type","name","argidx"),&VisualScript::custom_signal_get_argument_type); - ClassDB::bind_method(_MD("custom_signal_set_argument_name","name","argidx","argname"),&VisualScript::custom_signal_set_argument_name); - ClassDB::bind_method(_MD("custom_signal_get_argument_name","name","argidx"),&VisualScript::custom_signal_get_argument_name); - ClassDB::bind_method(_MD("custom_signal_remove_argument","argidx"),&VisualScript::custom_signal_remove_argument); - ClassDB::bind_method(_MD("custom_signal_get_argument_count","name"),&VisualScript::custom_signal_get_argument_count); - ClassDB::bind_method(_MD("custom_signal_swap_argument","name","argidx","withidx"),&VisualScript::custom_signal_swap_argument); - ClassDB::bind_method(_MD("remove_custom_signal","name"),&VisualScript::remove_custom_signal); - ClassDB::bind_method(_MD("rename_custom_signal","name","new_name"),&VisualScript::rename_custom_signal); + ClassDB::bind_method(D_METHOD("add_custom_signal","name"),&VisualScript::add_custom_signal); + ClassDB::bind_method(D_METHOD("has_custom_signal","name"),&VisualScript::has_custom_signal); + ClassDB::bind_method(D_METHOD("custom_signal_add_argument","name","type","argname","index"),&VisualScript::custom_signal_add_argument,DEFVAL(-1)); + ClassDB::bind_method(D_METHOD("custom_signal_set_argument_type","name","argidx","type"),&VisualScript::custom_signal_set_argument_type); + ClassDB::bind_method(D_METHOD("custom_signal_get_argument_type","name","argidx"),&VisualScript::custom_signal_get_argument_type); + ClassDB::bind_method(D_METHOD("custom_signal_set_argument_name","name","argidx","argname"),&VisualScript::custom_signal_set_argument_name); + ClassDB::bind_method(D_METHOD("custom_signal_get_argument_name","name","argidx"),&VisualScript::custom_signal_get_argument_name); + ClassDB::bind_method(D_METHOD("custom_signal_remove_argument","argidx"),&VisualScript::custom_signal_remove_argument); + ClassDB::bind_method(D_METHOD("custom_signal_get_argument_count","name"),&VisualScript::custom_signal_get_argument_count); + ClassDB::bind_method(D_METHOD("custom_signal_swap_argument","name","argidx","withidx"),&VisualScript::custom_signal_swap_argument); + ClassDB::bind_method(D_METHOD("remove_custom_signal","name"),&VisualScript::remove_custom_signal); + ClassDB::bind_method(D_METHOD("rename_custom_signal","name","new_name"),&VisualScript::rename_custom_signal); - //ClassDB::bind_method(_MD("set_variable_info","name","info"),&VScript::set_variable_info); - //ClassDB::bind_method(_MD("get_variable_info","name"),&VScript::set_variable_info); + //ClassDB::bind_method(D_METHOD("set_variable_info","name","info"),&VScript::set_variable_info); + //ClassDB::bind_method(D_METHOD("get_variable_info","name"),&VScript::set_variable_info); - ClassDB::bind_method(_MD("set_instance_base_type","type"),&VisualScript::set_instance_base_type); + ClassDB::bind_method(D_METHOD("set_instance_base_type","type"),&VisualScript::set_instance_base_type); - ClassDB::bind_method(_MD("_set_data","data"),&VisualScript::_set_data); - ClassDB::bind_method(_MD("_get_data"),&VisualScript::_get_data); + ClassDB::bind_method(D_METHOD("_set_data","data"),&VisualScript::_set_data); + ClassDB::bind_method(D_METHOD("_get_data"),&VisualScript::_get_data); - ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY,"data",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_data"),_SCS("_get_data")); + ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY,"data",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"_set_data","_get_data"); ADD_SIGNAL(MethodInfo("node_ports_changed",PropertyInfo(Variant::STRING,"function"),PropertyInfo(Variant::INT,"id"))); } @@ -2436,9 +2436,9 @@ Variant VisualScriptFunctionState::resume(Array p_args) { void VisualScriptFunctionState::_bind_methods() { - ClassDB::bind_method(_MD("connect_to_signal","obj","signals","args"),&VisualScriptFunctionState::connect_to_signal); - ClassDB::bind_method(_MD("resume:Array","args"),&VisualScriptFunctionState::resume,DEFVAL(Variant())); - ClassDB::bind_method(_MD("is_valid"),&VisualScriptFunctionState::is_valid); + ClassDB::bind_method(D_METHOD("connect_to_signal","obj","signals","args"),&VisualScriptFunctionState::connect_to_signal); + ClassDB::bind_method(D_METHOD("resume:Array","args"),&VisualScriptFunctionState::resume,DEFVAL(Variant())); + ClassDB::bind_method(D_METHOD("is_valid"),&VisualScriptFunctionState::is_valid); ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"_signal_callback",&VisualScriptFunctionState::_signal_callback,MethodInfo("_signal_callback")); } @@ -2631,7 +2631,7 @@ void VisualScriptLanguage::debug_get_stack_level_locals(int p_level,List<String> const StringName *f = _call_stack[l].function; ERR_FAIL_COND(!_call_stack[l].instance->functions.has(*f)); -// VisualScriptInstance::Function *func = &_call_stack[l].instance->functions[*f]; + //VisualScriptInstance::Function *func = &_call_stack[l].instance->functions[*f]; VisualScriptNodeInstance *node =_call_stack[l].instance->instances[*_call_stack[l].current_id]; ERR_FAIL_COND(!node); diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp index 27242384a..f9780400d 100644 --- a/modules/visual_script/visual_script_builtin_funcs.cpp +++ b/modules/visual_script/visual_script_builtin_funcs.cpp @@ -1,6 +1,6 @@ #include "visual_script_builtin_funcs.h" #include "math_funcs.h" -#include "object_type_db.h" +#include "class_db.h" #include "reference.h" #include "func_ref.h" #include "os/os.h" @@ -329,7 +329,7 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const case LOGIC_CLAMP: { if (p_idx==0) return PropertyInfo(Variant::REAL,"a"); - else if (p_idx==0) + else if (p_idx==0) // FIXME: is it ok to test p_idx == 0 twice? return PropertyInfo(Variant::REAL,"min"); else return PropertyInfo(Variant::REAL,"max"); @@ -610,85 +610,85 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func,const Variant** p_inp case VisualScriptBuiltinFunc::MATH_SIN: { VALIDATE_ARG_NUM(0); - *r_return=Math::sin(*p_inputs[0]); + *r_return=Math::sin((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_COS: { VALIDATE_ARG_NUM(0); - *r_return=Math::cos(*p_inputs[0]); + *r_return=Math::cos((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_TAN: { VALIDATE_ARG_NUM(0); - *r_return=Math::tan(*p_inputs[0]); + *r_return=Math::tan((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_SINH: { VALIDATE_ARG_NUM(0); - *r_return=Math::sinh(*p_inputs[0]); + *r_return=Math::sinh((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_COSH: { VALIDATE_ARG_NUM(0); - *r_return=Math::cosh(*p_inputs[0]); + *r_return=Math::cosh((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_TANH: { VALIDATE_ARG_NUM(0); - *r_return=Math::tanh(*p_inputs[0]); + *r_return=Math::tanh((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ASIN: { VALIDATE_ARG_NUM(0); - *r_return=Math::asin(*p_inputs[0]); + *r_return=Math::asin((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ACOS: { VALIDATE_ARG_NUM(0); - *r_return=Math::acos(*p_inputs[0]); + *r_return=Math::acos((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ATAN: { VALIDATE_ARG_NUM(0); - *r_return=Math::atan(*p_inputs[0]); + *r_return=Math::atan((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ATAN2: { VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - *r_return=Math::atan2(*p_inputs[0],*p_inputs[1]); + *r_return=Math::atan2((double)*p_inputs[0],(double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_SQRT: { VALIDATE_ARG_NUM(0); - *r_return=Math::sqrt(*p_inputs[0]); + *r_return=Math::sqrt((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_FMOD: { VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - *r_return=Math::fmod(*p_inputs[0],*p_inputs[1]); + *r_return=Math::fmod((double)*p_inputs[0],(double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_FPOSMOD: { VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - *r_return=Math::fposmod(*p_inputs[0],*p_inputs[1]); + *r_return=Math::fposmod((double)*p_inputs[0],(double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_FLOOR: { VALIDATE_ARG_NUM(0); - *r_return=Math::floor(*p_inputs[0]); + *r_return=Math::floor((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_CEIL: { VALIDATE_ARG_NUM(0); - *r_return=Math::ceil(*p_inputs[0]); + *r_return=Math::ceil((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ROUND: { VALIDATE_ARG_NUM(0); - *r_return=Math::round(*p_inputs[0]); + *r_return=Math::round((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ABS: { @@ -730,58 +730,58 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func,const Variant** p_inp VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - *r_return=Math::pow(*p_inputs[0],*p_inputs[1]); + *r_return=Math::pow((double)*p_inputs[0],(double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_LOG: { VALIDATE_ARG_NUM(0); - *r_return=Math::log(*p_inputs[0]); + *r_return=Math::log((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_EXP: { VALIDATE_ARG_NUM(0); - *r_return=Math::exp(*p_inputs[0]); + *r_return=Math::exp((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ISNAN: { VALIDATE_ARG_NUM(0); - *r_return=Math::is_nan(*p_inputs[0]); + *r_return=Math::is_nan((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ISINF: { VALIDATE_ARG_NUM(0); - *r_return=Math::is_inf(*p_inputs[0]); + *r_return=Math::is_inf((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_EASE: { VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - *r_return=Math::ease(*p_inputs[0],*p_inputs[1]); + *r_return=Math::ease((double)*p_inputs[0],(double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_DECIMALS: { VALIDATE_ARG_NUM(0); - *r_return=Math::step_decimals(*p_inputs[0]); + *r_return=Math::step_decimals((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_STEPIFY: { VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - *r_return=Math::stepify(*p_inputs[0],*p_inputs[1]); + *r_return=Math::stepify((double)*p_inputs[0],(double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_LERP: { VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); - *r_return=Math::lerp(*p_inputs[0],*p_inputs[1],*p_inputs[2]); + *r_return=Math::lerp((double)*p_inputs[0],(double)*p_inputs[1],(double)*p_inputs[2]); } break; case VisualScriptBuiltinFunc::MATH_DECTIME: { VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); - *r_return=Math::dectime(*p_inputs[0],*p_inputs[1],*p_inputs[2]); + *r_return=Math::dectime((double)*p_inputs[0],(double)*p_inputs[1],(double)*p_inputs[2]); } break; case VisualScriptBuiltinFunc::MATH_RANDOMIZE: { Math::randomize(); @@ -797,19 +797,19 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func,const Variant** p_inp VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - *r_return=Math::random(*p_inputs[0],*p_inputs[1]); + *r_return=Math::random((double)*p_inputs[0],(double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_SEED: { VALIDATE_ARG_NUM(0); - uint32_t seed=*p_inputs[0]; + uint64_t seed=*p_inputs[0]; Math::seed(seed); } break; case VisualScriptBuiltinFunc::MATH_RANDSEED: { VALIDATE_ARG_NUM(0); - uint32_t seed=*p_inputs[0]; + uint64_t seed=*p_inputs[0]; int ret = Math::rand_from_seed(&seed); Array reta; reta.push_back(ret); @@ -820,22 +820,22 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func,const Variant** p_inp case VisualScriptBuiltinFunc::MATH_DEG2RAD: { VALIDATE_ARG_NUM(0); - *r_return=Math::deg2rad(*p_inputs[0]); + *r_return=Math::deg2rad((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_RAD2DEG: { VALIDATE_ARG_NUM(0); - *r_return=Math::rad2deg(*p_inputs[0]); + *r_return=Math::rad2deg((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_LINEAR2DB: { VALIDATE_ARG_NUM(0); - *r_return=Math::linear2db(*p_inputs[0]); + *r_return=Math::linear2db((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_DB2LINEAR: { VALIDATE_ARG_NUM(0); - *r_return=Math::db2linear(*p_inputs[0]); + *r_return=Math::db2linear((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::LOGIC_MAX: { @@ -1166,8 +1166,8 @@ VisualScriptNodeInstance* VisualScriptBuiltinFunc::instance(VisualScriptInstance void VisualScriptBuiltinFunc::_bind_methods() { - ClassDB::bind_method(_MD("set_func","which"),&VisualScriptBuiltinFunc::set_func); - ClassDB::bind_method(_MD("get_func"),&VisualScriptBuiltinFunc::get_func); + ClassDB::bind_method(D_METHOD("set_func","which"),&VisualScriptBuiltinFunc::set_func); + ClassDB::bind_method(D_METHOD("get_func"),&VisualScriptBuiltinFunc::get_func); String cc; @@ -1177,7 +1177,7 @@ void VisualScriptBuiltinFunc::_bind_methods() { cc+=","; cc+=func_name[i]; } - ADD_PROPERTY(PropertyInfo(Variant::INT,"function",PROPERTY_HINT_ENUM,cc),_SCS("set_func"),_SCS("get_func")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"function",PROPERTY_HINT_ENUM,cc),"set_func","get_func"); } VisualScriptBuiltinFunc::VisualScriptBuiltinFunc() { diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 6f3ea3b4a..eadc9a889 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -590,9 +590,9 @@ void VisualScriptEditor::_update_graph(int p_only_id) { t=type_icons[left_type]; } if (t.is_valid()) { - TextureFrame *tf = memnew(TextureFrame); + TextureRect *tf = memnew(TextureRect); tf->set_texture(t); - tf->set_stretch_mode(TextureFrame::STRETCH_KEEP_CENTERED); + tf->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED); hbc->add_child(tf); } @@ -657,9 +657,9 @@ void VisualScriptEditor::_update_graph(int p_only_id) { t=type_icons[right_type]; } if (t.is_valid()) { - TextureFrame *tf = memnew(TextureFrame); + TextureRect *tf = memnew(TextureRect); tf->set_texture(t); - tf->set_stretch_mode(TextureFrame::STRETCH_KEEP_CENTERED); + tf->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED); hbc->add_child(tf); } @@ -822,7 +822,7 @@ void VisualScriptEditor::_member_selected() { selected=ti->get_metadata(0); -// print_line("selected: "+String(selected)); + //print_line("selected: "+String(selected)); if (ti->get_parent()==members->get_root()->get_children()) { @@ -1136,9 +1136,11 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt undo_redo->add_undo_method(script.ptr(),"data_connect",name,E->get().from_node,E->get().from_port,E->get().to_node,E->get().to_port); } - //for(int i=0;i<script->function_get_argument_count(name);i++) { - //// undo_redo->add_undo_method(script.ptr(),"function_add_argument",name,script->function_get_argument_name(name,i),script->function_get_argument_type(name,i)); - //} + /* + for(int i=0;i<script->function_get_argument_count(name);i++) { + undo_redo->add_undo_method(script.ptr(),"function_add_argument",name,script->function_get_argument_name(name,i),script->function_get_argument_type(name,i)); + } + */ undo_redo->add_do_method(this,"_update_members"); undo_redo->add_undo_method(this,"_update_members"); undo_redo->add_do_method(this,"_update_graph"); @@ -1776,7 +1778,7 @@ void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat if (node) { graph->set_selected(node); _node_selected(node); - } + } } if (d.has("type") && String(d["type"])=="resource") { @@ -1916,7 +1918,7 @@ void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat Ref<VisualScriptFunctionCall> call; call.instance(); call->set_call_mode(VisualScriptFunctionCall::CALL_MODE_NODE_PATH); - call->set_base_path(sn->get_path_to(node));; + call->set_base_path(sn->get_path_to(node)); call->set_base_type(node->get_class()); n=call; @@ -3082,7 +3084,7 @@ void VisualScriptEditor::_menu_option(int p_what) { //popup disappearing grabs focus to owner, so use call deferred node_filter->call_deferred("grab_focus"); node_filter->call_deferred("select_all"); - } break; + } break; case EDIT_COPY_NODES: case EDIT_CUT_NODES: { @@ -3346,8 +3348,8 @@ VisualScriptEditor::VisualScriptEditor() { node_filter->connect("text_changed",this,"_node_filter_changed"); hbc_nodes->add_child(node_filter); node_filter->set_h_size_flags(SIZE_EXPAND_FILL); - node_filter_icon = memnew( TextureFrame ); - node_filter_icon->set_stretch_mode(TextureFrame::STRETCH_KEEP_CENTERED); + node_filter_icon = memnew( TextureRect ); + node_filter_icon->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED); hbc_nodes->add_child(node_filter_icon); vbc_nodes->add_child(hbc_nodes); diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h index e120bdc65..1dc62b3e6 100644 --- a/modules/visual_script/visual_script_editor.h +++ b/modules/visual_script/visual_script_editor.h @@ -58,7 +58,7 @@ class VisualScriptEditor : public ScriptEditorBase { GraphEdit *graph; LineEdit *node_filter; - TextureFrame *node_filter_icon; + TextureRect *node_filter_icon; VisualScriptEditorSignalEdit *signal_editor; diff --git a/modules/visual_script/visual_script_expression.cpp b/modules/visual_script/visual_script_expression.cpp index cc3b5f217..f14aee5d7 100644 --- a/modules/visual_script/visual_script_expression.cpp +++ b/modules/visual_script/visual_script_expression.cpp @@ -558,6 +558,12 @@ Error VisualScriptExpression::_get_token(Token& r_token) { } else if (id=="PI") { r_token.type=TK_CONSTANT; r_token.value=Math_PI; + } else if (id == "INF") { + r_token.type = TK_CONSTANT; + r_token.value = Math_INF; + } else if (id == "NAN") { + r_token.type = TK_CONSTANT; + r_token.value = Math_NAN; } else if (id=="not") { r_token.type=TK_OP_NOT; } else if (id=="or") { diff --git a/modules/visual_script/visual_script_flow_control.cpp b/modules/visual_script/visual_script_flow_control.cpp index 0e526f8a4..93e395f0f 100644 --- a/modules/visual_script/visual_script_flow_control.cpp +++ b/modules/visual_script/visual_script_flow_control.cpp @@ -1,6 +1,6 @@ #include "visual_script_flow_control.h" #include "os/keyboard.h" -#include "globals.h" +#include "global_config.h" ////////////////////////////////////////// @@ -81,18 +81,18 @@ bool VisualScriptReturn::is_return_value_enabled() const { void VisualScriptReturn::_bind_methods() { - ClassDB::bind_method(_MD("set_return_type","type"),&VisualScriptReturn::set_return_type); - ClassDB::bind_method(_MD("get_return_type"),&VisualScriptReturn::get_return_type); - ClassDB::bind_method(_MD("set_enable_return_value","enable"),&VisualScriptReturn::set_enable_return_value); - ClassDB::bind_method(_MD("is_return_value_enabled"),&VisualScriptReturn::is_return_value_enabled); + ClassDB::bind_method(D_METHOD("set_return_type","type"),&VisualScriptReturn::set_return_type); + ClassDB::bind_method(D_METHOD("get_return_type"),&VisualScriptReturn::get_return_type); + ClassDB::bind_method(D_METHOD("set_enable_return_value","enable"),&VisualScriptReturn::set_enable_return_value); + ClassDB::bind_method(D_METHOD("is_return_value_enabled"),&VisualScriptReturn::is_return_value_enabled); String argt="Any"; for(int i=1;i<Variant::VARIANT_MAX;i++) { argt+=","+Variant::get_type_name(Variant::Type(i)); } - ADD_PROPERTY(PropertyInfo(Variant::BOOL,"return_value/enabled"),_SCS("set_enable_return_value"),_SCS("is_return_value_enabled")); - ADD_PROPERTY(PropertyInfo(Variant::INT,"return_value/type",PROPERTY_HINT_ENUM,argt),_SCS("set_return_type"),_SCS("get_return_type")); + ADD_PROPERTY(PropertyInfo(Variant::BOOL,"return_value/enabled"),"set_enable_return_value","is_return_value_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::INT,"return_value/type",PROPERTY_HINT_ENUM,argt),"set_return_type","get_return_type"); } @@ -544,10 +544,10 @@ int VisualScriptSequence::get_steps() const { void VisualScriptSequence::_bind_methods() { - ClassDB::bind_method(_MD("set_steps","steps"),&VisualScriptSequence::set_steps); - ClassDB::bind_method(_MD("get_steps"),&VisualScriptSequence::get_steps); + ClassDB::bind_method(D_METHOD("set_steps","steps"),&VisualScriptSequence::set_steps); + ClassDB::bind_method(D_METHOD("get_steps"),&VisualScriptSequence::get_steps); - ADD_PROPERTY(PropertyInfo(Variant::INT,"steps",PROPERTY_HINT_RANGE,"1,64,1"),_SCS("set_steps"),_SCS("get_steps")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"steps",PROPERTY_HINT_RANGE,"1,64,1"),"set_steps","get_steps"); } @@ -1893,11 +1893,11 @@ VisualScriptNodeInstance* VisualScriptTypeCast::instance(VisualScriptInstance* p void VisualScriptTypeCast::_bind_methods() { - ClassDB::bind_method(_MD("set_base_type","type"),&VisualScriptTypeCast::set_base_type); - ClassDB::bind_method(_MD("get_base_type"),&VisualScriptTypeCast::get_base_type); + ClassDB::bind_method(D_METHOD("set_base_type","type"),&VisualScriptTypeCast::set_base_type); + ClassDB::bind_method(D_METHOD("get_base_type"),&VisualScriptTypeCast::get_base_type); - ClassDB::bind_method(_MD("set_base_script","path"),&VisualScriptTypeCast::set_base_script); - ClassDB::bind_method(_MD("get_base_script"),&VisualScriptTypeCast::get_base_script); + ClassDB::bind_method(D_METHOD("set_base_script","path"),&VisualScriptTypeCast::set_base_script); + ClassDB::bind_method(D_METHOD("get_base_script"),&VisualScriptTypeCast::get_base_script); List<String> script_extensions; @@ -1912,8 +1912,8 @@ void VisualScriptTypeCast::_bind_methods() { script_ext_hint+="*."+E->get(); } - ADD_PROPERTY(PropertyInfo(Variant::STRING,"function/base_type",PROPERTY_HINT_TYPE_STRING,"Object"),_SCS("set_base_type"),_SCS("get_base_type")); - ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/base_script",PROPERTY_HINT_FILE,script_ext_hint),_SCS("set_base_script"),_SCS("get_base_script")); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"function/base_type",PROPERTY_HINT_TYPE_STRING,"Object"),"set_base_type","get_base_type"); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/base_script",PROPERTY_HINT_FILE,script_ext_hint),"set_base_script","get_base_script"); } diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp index 9f3ba8a8c..fd91385f9 100644 --- a/modules/visual_script/visual_script_func_nodes.cpp +++ b/modules/visual_script/visual_script_func_nodes.cpp @@ -4,7 +4,7 @@ #include "scene/main/node.h" #include "visual_script_nodes.h" #include "io/resource_loader.h" -#include "globals.h" +#include "global_config.h" ////////////////////////////////////////// ////////////////CALL////////////////////// @@ -396,7 +396,7 @@ void VisualScriptFunctionCall::_update_method_cache() { } -// print_line("BASE: "+String(type)+" FUNC: "+String(function)); + //print_line("BASE: "+String(type)+" FUNC: "+String(function)); MethodBind *mb = ClassDB::get_method(type,function); if (mb) { use_default_args=mb->get_default_argument_count(); @@ -687,38 +687,38 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo& property) const void VisualScriptFunctionCall::_bind_methods() { - ClassDB::bind_method(_MD("set_base_type","base_type"),&VisualScriptFunctionCall::set_base_type); - ClassDB::bind_method(_MD("get_base_type"),&VisualScriptFunctionCall::get_base_type); + ClassDB::bind_method(D_METHOD("set_base_type","base_type"),&VisualScriptFunctionCall::set_base_type); + ClassDB::bind_method(D_METHOD("get_base_type"),&VisualScriptFunctionCall::get_base_type); - ClassDB::bind_method(_MD("set_base_script","base_script"),&VisualScriptFunctionCall::set_base_script); - ClassDB::bind_method(_MD("get_base_script"),&VisualScriptFunctionCall::get_base_script); + ClassDB::bind_method(D_METHOD("set_base_script","base_script"),&VisualScriptFunctionCall::set_base_script); + ClassDB::bind_method(D_METHOD("get_base_script"),&VisualScriptFunctionCall::get_base_script); - ClassDB::bind_method(_MD("set_basic_type","basic_type"),&VisualScriptFunctionCall::set_basic_type); - ClassDB::bind_method(_MD("get_basic_type"),&VisualScriptFunctionCall::get_basic_type); + ClassDB::bind_method(D_METHOD("set_basic_type","basic_type"),&VisualScriptFunctionCall::set_basic_type); + ClassDB::bind_method(D_METHOD("get_basic_type"),&VisualScriptFunctionCall::get_basic_type); - ClassDB::bind_method(_MD("set_singleton","singleton"),&VisualScriptFunctionCall::set_singleton); - ClassDB::bind_method(_MD("get_singleton"),&VisualScriptFunctionCall::get_singleton); + ClassDB::bind_method(D_METHOD("set_singleton","singleton"),&VisualScriptFunctionCall::set_singleton); + ClassDB::bind_method(D_METHOD("get_singleton"),&VisualScriptFunctionCall::get_singleton); - ClassDB::bind_method(_MD("set_function","function"),&VisualScriptFunctionCall::set_function); - ClassDB::bind_method(_MD("get_function"),&VisualScriptFunctionCall::get_function); + ClassDB::bind_method(D_METHOD("set_function","function"),&VisualScriptFunctionCall::set_function); + ClassDB::bind_method(D_METHOD("get_function"),&VisualScriptFunctionCall::get_function); - ClassDB::bind_method(_MD("set_call_mode","mode"),&VisualScriptFunctionCall::set_call_mode); - ClassDB::bind_method(_MD("get_call_mode"),&VisualScriptFunctionCall::get_call_mode); + ClassDB::bind_method(D_METHOD("set_call_mode","mode"),&VisualScriptFunctionCall::set_call_mode); + ClassDB::bind_method(D_METHOD("get_call_mode"),&VisualScriptFunctionCall::get_call_mode); - ClassDB::bind_method(_MD("set_base_path","base_path"),&VisualScriptFunctionCall::set_base_path); - ClassDB::bind_method(_MD("get_base_path"),&VisualScriptFunctionCall::get_base_path); + ClassDB::bind_method(D_METHOD("set_base_path","base_path"),&VisualScriptFunctionCall::set_base_path); + ClassDB::bind_method(D_METHOD("get_base_path"),&VisualScriptFunctionCall::get_base_path); - ClassDB::bind_method(_MD("set_use_default_args","amount"),&VisualScriptFunctionCall::set_use_default_args); - ClassDB::bind_method(_MD("get_use_default_args"),&VisualScriptFunctionCall::get_use_default_args); + ClassDB::bind_method(D_METHOD("set_use_default_args","amount"),&VisualScriptFunctionCall::set_use_default_args); + ClassDB::bind_method(D_METHOD("get_use_default_args"),&VisualScriptFunctionCall::get_use_default_args); - ClassDB::bind_method(_MD("_set_argument_cache","argument_cache"),&VisualScriptFunctionCall::_set_argument_cache); - ClassDB::bind_method(_MD("_get_argument_cache"),&VisualScriptFunctionCall::_get_argument_cache); + ClassDB::bind_method(D_METHOD("_set_argument_cache","argument_cache"),&VisualScriptFunctionCall::_set_argument_cache); + ClassDB::bind_method(D_METHOD("_get_argument_cache"),&VisualScriptFunctionCall::_get_argument_cache); - ClassDB::bind_method(_MD("set_rpc_call_mode","mode"),&VisualScriptFunctionCall::set_rpc_call_mode); - ClassDB::bind_method(_MD("get_rpc_call_mode"),&VisualScriptFunctionCall::get_rpc_call_mode); + ClassDB::bind_method(D_METHOD("set_rpc_call_mode","mode"),&VisualScriptFunctionCall::set_rpc_call_mode); + ClassDB::bind_method(D_METHOD("get_rpc_call_mode"),&VisualScriptFunctionCall::get_rpc_call_mode); - ClassDB::bind_method(_MD("set_validate","enable"),&VisualScriptFunctionCall::set_validate); - ClassDB::bind_method(_MD("get_validate"),&VisualScriptFunctionCall::get_validate); + ClassDB::bind_method(D_METHOD("set_validate","enable"),&VisualScriptFunctionCall::set_validate); + ClassDB::bind_method(D_METHOD("get_validate"),&VisualScriptFunctionCall::get_validate); String bt; for(int i=0;i<Variant::VARIANT_MAX;i++) { @@ -743,17 +743,17 @@ void VisualScriptFunctionCall::_bind_methods() { - ADD_PROPERTY(PropertyInfo(Variant::INT,"function/call_mode",PROPERTY_HINT_ENUM,"Self,Node Path,Instance,Basic Type,Singleton"),_SCS("set_call_mode"),_SCS("get_call_mode")); - ADD_PROPERTY(PropertyInfo(Variant::STRING,"function/base_type",PROPERTY_HINT_TYPE_STRING,"Object"),_SCS("set_base_type"),_SCS("get_base_type")); - ADD_PROPERTY(PropertyInfo(Variant::STRING,"function/base_script",PROPERTY_HINT_FILE,script_ext_hint),_SCS("set_base_script"),_SCS("get_base_script")); - ADD_PROPERTY(PropertyInfo(Variant::STRING,"function/singleton"),_SCS("set_singleton"),_SCS("get_singleton")); - ADD_PROPERTY(PropertyInfo(Variant::INT,"function/basic_type",PROPERTY_HINT_ENUM,bt),_SCS("set_basic_type"),_SCS("get_basic_type")); - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH,"function/node_path",PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE),_SCS("set_base_path"),_SCS("get_base_path")); - ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY,"function/argument_cache",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_argument_cache"),_SCS("_get_argument_cache")); - ADD_PROPERTY(PropertyInfo(Variant::STRING,"function/function"),_SCS("set_function"),_SCS("get_function")); //when set, if loaded properly, will override argument count. - ADD_PROPERTY(PropertyInfo(Variant::INT,"function/use_default_args"),_SCS("set_use_default_args"),_SCS("get_use_default_args")); - ADD_PROPERTY(PropertyInfo(Variant::BOOL,"function/validate"),_SCS("set_validate"),_SCS("get_validate")); - ADD_PROPERTY(PropertyInfo(Variant::INT,"rpc/call_mode",PROPERTY_HINT_ENUM,"Disabled,Reliable,Unreliable,ReliableToID,UnreliableToID"),_SCS("set_rpc_call_mode"),_SCS("get_rpc_call_mode")); //when set, if loaded properly, will override argument count. + ADD_PROPERTY(PropertyInfo(Variant::INT,"function/call_mode",PROPERTY_HINT_ENUM,"Self,Node Path,Instance,Basic Type,Singleton"),"set_call_mode","get_call_mode"); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"function/base_type",PROPERTY_HINT_TYPE_STRING,"Object"),"set_base_type","get_base_type"); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"function/base_script",PROPERTY_HINT_FILE,script_ext_hint),"set_base_script","get_base_script"); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"function/singleton"),"set_singleton","get_singleton"); + ADD_PROPERTY(PropertyInfo(Variant::INT,"function/basic_type",PROPERTY_HINT_ENUM,bt),"set_basic_type","get_basic_type"); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH,"function/node_path",PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE),"set_base_path","get_base_path"); + ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY,"function/argument_cache",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"_set_argument_cache","_get_argument_cache"); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"function/function"),"set_function","get_function"); //when set, if loaded properly, will override argument count. + ADD_PROPERTY(PropertyInfo(Variant::INT,"function/use_default_args"),"set_use_default_args","get_use_default_args"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL,"function/validate"),"set_validate","get_validate"); + ADD_PROPERTY(PropertyInfo(Variant::INT,"rpc/call_mode",PROPERTY_HINT_ENUM,"Disabled,Reliable,Unreliable,ReliableToID,UnreliableToID"),"set_rpc_call_mode","get_rpc_call_mode"); //when set, if loaded properly, will override argument count. BIND_CONSTANT( CALL_MODE_SELF ); BIND_CONSTANT( CALL_MODE_NODE_PATH); @@ -1453,29 +1453,29 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo& property) const { void VisualScriptPropertySet::_bind_methods() { - ClassDB::bind_method(_MD("set_base_type","base_type"),&VisualScriptPropertySet::set_base_type); - ClassDB::bind_method(_MD("get_base_type"),&VisualScriptPropertySet::get_base_type); + ClassDB::bind_method(D_METHOD("set_base_type","base_type"),&VisualScriptPropertySet::set_base_type); + ClassDB::bind_method(D_METHOD("get_base_type"),&VisualScriptPropertySet::get_base_type); - ClassDB::bind_method(_MD("set_base_script","base_script"),&VisualScriptPropertySet::set_base_script); - ClassDB::bind_method(_MD("get_base_script"),&VisualScriptPropertySet::get_base_script); + ClassDB::bind_method(D_METHOD("set_base_script","base_script"),&VisualScriptPropertySet::set_base_script); + ClassDB::bind_method(D_METHOD("get_base_script"),&VisualScriptPropertySet::get_base_script); - ClassDB::bind_method(_MD("set_basic_type","basic_type"),&VisualScriptPropertySet::set_basic_type); - ClassDB::bind_method(_MD("get_basic_type"),&VisualScriptPropertySet::get_basic_type); + ClassDB::bind_method(D_METHOD("set_basic_type","basic_type"),&VisualScriptPropertySet::set_basic_type); + ClassDB::bind_method(D_METHOD("get_basic_type"),&VisualScriptPropertySet::get_basic_type); - ClassDB::bind_method(_MD("_set_type_cache","type_cache"),&VisualScriptPropertySet::_set_type_cache); - ClassDB::bind_method(_MD("_get_type_cache"),&VisualScriptPropertySet::_get_type_cache); + ClassDB::bind_method(D_METHOD("_set_type_cache","type_cache"),&VisualScriptPropertySet::_set_type_cache); + ClassDB::bind_method(D_METHOD("_get_type_cache"),&VisualScriptPropertySet::_get_type_cache); - ClassDB::bind_method(_MD("set_event_type","event_type"),&VisualScriptPropertySet::set_event_type); - ClassDB::bind_method(_MD("get_event_type"),&VisualScriptPropertySet::get_event_type); + ClassDB::bind_method(D_METHOD("set_event_type","event_type"),&VisualScriptPropertySet::set_event_type); + ClassDB::bind_method(D_METHOD("get_event_type"),&VisualScriptPropertySet::get_event_type); - ClassDB::bind_method(_MD("set_property","property"),&VisualScriptPropertySet::set_property); - ClassDB::bind_method(_MD("get_property"),&VisualScriptPropertySet::get_property); + ClassDB::bind_method(D_METHOD("set_property","property"),&VisualScriptPropertySet::set_property); + ClassDB::bind_method(D_METHOD("get_property"),&VisualScriptPropertySet::get_property); - ClassDB::bind_method(_MD("set_call_mode","mode"),&VisualScriptPropertySet::set_call_mode); - ClassDB::bind_method(_MD("get_call_mode"),&VisualScriptPropertySet::get_call_mode); + ClassDB::bind_method(D_METHOD("set_call_mode","mode"),&VisualScriptPropertySet::set_call_mode); + ClassDB::bind_method(D_METHOD("get_call_mode"),&VisualScriptPropertySet::get_call_mode); - ClassDB::bind_method(_MD("set_base_path","base_path"),&VisualScriptPropertySet::set_base_path); - ClassDB::bind_method(_MD("get_base_path"),&VisualScriptPropertySet::get_base_path); + ClassDB::bind_method(D_METHOD("set_base_path","base_path"),&VisualScriptPropertySet::set_base_path); + ClassDB::bind_method(D_METHOD("get_base_path"),&VisualScriptPropertySet::get_base_path); @@ -1507,14 +1507,14 @@ void VisualScriptPropertySet::_bind_methods() { script_ext_hint+="*."+E->get(); } - ADD_PROPERTY(PropertyInfo(Variant::INT,"property/set_mode",PROPERTY_HINT_ENUM,"Self,Node Path,Instance,Basic Type"),_SCS("set_call_mode"),_SCS("get_call_mode")); - ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/base_type",PROPERTY_HINT_TYPE_STRING,"Object"),_SCS("set_base_type"),_SCS("get_base_type")); - ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/base_script",PROPERTY_HINT_FILE,script_ext_hint),_SCS("set_base_script"),_SCS("get_base_script")); - ADD_PROPERTY(PropertyInfo(Variant::INT,"property/type_cache",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_type_cache"),_SCS("_get_type_cache")); - ADD_PROPERTY(PropertyInfo(Variant::INT,"property/basic_type",PROPERTY_HINT_ENUM,bt),_SCS("set_basic_type"),_SCS("get_basic_type")); - ADD_PROPERTY(PropertyInfo(Variant::INT,"property/event_type",PROPERTY_HINT_ENUM,et),_SCS("set_event_type"),_SCS("get_event_type")); - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH,"property/node_path",PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE),_SCS("set_base_path"),_SCS("get_base_path")); - ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/property"),_SCS("set_property"),_SCS("get_property")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"property/set_mode",PROPERTY_HINT_ENUM,"Self,Node Path,Instance,Basic Type"),"set_call_mode","get_call_mode"); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/base_type",PROPERTY_HINT_TYPE_STRING,"Object"),"set_base_type","get_base_type"); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/base_script",PROPERTY_HINT_FILE,script_ext_hint),"set_base_script","get_base_script"); + ADD_PROPERTY(PropertyInfo(Variant::INT,"property/type_cache",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"_set_type_cache","_get_type_cache"); + ADD_PROPERTY(PropertyInfo(Variant::INT,"property/basic_type",PROPERTY_HINT_ENUM,bt),"set_basic_type","get_basic_type"); + ADD_PROPERTY(PropertyInfo(Variant::INT,"property/event_type",PROPERTY_HINT_ENUM,et),"set_event_type","get_event_type"); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH,"property/node_path",PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE),"set_base_path","get_base_path"); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/property"),"set_property","get_property"); BIND_CONSTANT( CALL_MODE_SELF ); BIND_CONSTANT( CALL_MODE_NODE_PATH); @@ -2117,30 +2117,30 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo& property) const { void VisualScriptPropertyGet::_bind_methods() { - ClassDB::bind_method(_MD("set_base_type","base_type"),&VisualScriptPropertyGet::set_base_type); - ClassDB::bind_method(_MD("get_base_type"),&VisualScriptPropertyGet::get_base_type); + ClassDB::bind_method(D_METHOD("set_base_type","base_type"),&VisualScriptPropertyGet::set_base_type); + ClassDB::bind_method(D_METHOD("get_base_type"),&VisualScriptPropertyGet::get_base_type); - ClassDB::bind_method(_MD("set_base_script","base_script"),&VisualScriptPropertyGet::set_base_script); - ClassDB::bind_method(_MD("get_base_script"),&VisualScriptPropertyGet::get_base_script); + ClassDB::bind_method(D_METHOD("set_base_script","base_script"),&VisualScriptPropertyGet::set_base_script); + ClassDB::bind_method(D_METHOD("get_base_script"),&VisualScriptPropertyGet::get_base_script); - ClassDB::bind_method(_MD("set_basic_type","basic_type"),&VisualScriptPropertyGet::set_basic_type); - ClassDB::bind_method(_MD("get_basic_type"),&VisualScriptPropertyGet::get_basic_type); + ClassDB::bind_method(D_METHOD("set_basic_type","basic_type"),&VisualScriptPropertyGet::set_basic_type); + ClassDB::bind_method(D_METHOD("get_basic_type"),&VisualScriptPropertyGet::get_basic_type); - ClassDB::bind_method(_MD("_set_type_cache","type_cache"),&VisualScriptPropertyGet::_set_type_cache); - ClassDB::bind_method(_MD("_get_type_cache"),&VisualScriptPropertyGet::_get_type_cache); + ClassDB::bind_method(D_METHOD("_set_type_cache","type_cache"),&VisualScriptPropertyGet::_set_type_cache); + ClassDB::bind_method(D_METHOD("_get_type_cache"),&VisualScriptPropertyGet::_get_type_cache); - ClassDB::bind_method(_MD("set_event_type","event_type"),&VisualScriptPropertyGet::set_event_type); - ClassDB::bind_method(_MD("get_event_type"),&VisualScriptPropertyGet::get_event_type); + ClassDB::bind_method(D_METHOD("set_event_type","event_type"),&VisualScriptPropertyGet::set_event_type); + ClassDB::bind_method(D_METHOD("get_event_type"),&VisualScriptPropertyGet::get_event_type); - ClassDB::bind_method(_MD("set_property","property"),&VisualScriptPropertyGet::set_property); - ClassDB::bind_method(_MD("get_property"),&VisualScriptPropertyGet::get_property); + ClassDB::bind_method(D_METHOD("set_property","property"),&VisualScriptPropertyGet::set_property); + ClassDB::bind_method(D_METHOD("get_property"),&VisualScriptPropertyGet::get_property); - ClassDB::bind_method(_MD("set_call_mode","mode"),&VisualScriptPropertyGet::set_call_mode); - ClassDB::bind_method(_MD("get_call_mode"),&VisualScriptPropertyGet::get_call_mode); + ClassDB::bind_method(D_METHOD("set_call_mode","mode"),&VisualScriptPropertyGet::set_call_mode); + ClassDB::bind_method(D_METHOD("get_call_mode"),&VisualScriptPropertyGet::get_call_mode); - ClassDB::bind_method(_MD("set_base_path","base_path"),&VisualScriptPropertyGet::set_base_path); - ClassDB::bind_method(_MD("get_base_path"),&VisualScriptPropertyGet::get_base_path); + ClassDB::bind_method(D_METHOD("set_base_path","base_path"),&VisualScriptPropertyGet::set_base_path); + ClassDB::bind_method(D_METHOD("get_base_path"),&VisualScriptPropertyGet::get_base_path); String bt; for(int i=0;i<Variant::VARIANT_MAX;i++) { @@ -2170,14 +2170,14 @@ void VisualScriptPropertyGet::_bind_methods() { script_ext_hint+="."+E->get(); } - ADD_PROPERTY(PropertyInfo(Variant::INT,"property/set_mode",PROPERTY_HINT_ENUM,"Self,Node Path,Instance,Basic Type"),_SCS("set_call_mode"),_SCS("get_call_mode")); - ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/base_type",PROPERTY_HINT_TYPE_STRING,"Object"),_SCS("set_base_type"),_SCS("get_base_type")); - ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/base_script",PROPERTY_HINT_FILE,script_ext_hint),_SCS("set_base_script"),_SCS("get_base_script")); - ADD_PROPERTY(PropertyInfo(Variant::INT,"property/type_cache",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_type_cache"),_SCS("_get_type_cache")); - ADD_PROPERTY(PropertyInfo(Variant::INT,"property/basic_type",PROPERTY_HINT_ENUM,bt),_SCS("set_basic_type"),_SCS("get_basic_type")); - ADD_PROPERTY(PropertyInfo(Variant::INT,"property/event_type",PROPERTY_HINT_ENUM,et),_SCS("set_event_type"),_SCS("get_event_type")); - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH,"property/node_path",PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE),_SCS("set_base_path"),_SCS("get_base_path")); - ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/property"),_SCS("set_property"),_SCS("get_property")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"property/set_mode",PROPERTY_HINT_ENUM,"Self,Node Path,Instance,Basic Type"),"set_call_mode","get_call_mode"); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/base_type",PROPERTY_HINT_TYPE_STRING,"Object"),"set_base_type","get_base_type"); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/base_script",PROPERTY_HINT_FILE,script_ext_hint),"set_base_script","get_base_script"); + ADD_PROPERTY(PropertyInfo(Variant::INT,"property/type_cache",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"_set_type_cache","_get_type_cache"); + ADD_PROPERTY(PropertyInfo(Variant::INT,"property/basic_type",PROPERTY_HINT_ENUM,bt),"set_basic_type","get_basic_type"); + ADD_PROPERTY(PropertyInfo(Variant::INT,"property/event_type",PROPERTY_HINT_ENUM,et),"set_event_type","get_event_type"); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH,"property/node_path",PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE),"set_base_path","get_base_path"); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/property"),"set_property","get_property"); BIND_CONSTANT( CALL_MODE_SELF ); BIND_CONSTANT( CALL_MODE_NODE_PATH); @@ -2420,11 +2420,11 @@ void VisualScriptEmitSignal::_validate_property(PropertyInfo& property) const { void VisualScriptEmitSignal::_bind_methods() { - ClassDB::bind_method(_MD("set_signal","name"),&VisualScriptEmitSignal::set_signal); - ClassDB::bind_method(_MD("get_signal"),&VisualScriptEmitSignal::get_signal); + ClassDB::bind_method(D_METHOD("set_signal","name"),&VisualScriptEmitSignal::set_signal); + ClassDB::bind_method(D_METHOD("get_signal"),&VisualScriptEmitSignal::get_signal); - ADD_PROPERTY(PropertyInfo(Variant::STRING,"signal/signal"),_SCS("set_signal"),_SCS("get_signal")); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"signal/signal"),"set_signal","get_signal"); } @@ -2508,7 +2508,7 @@ void register_visual_script_func_nodes() { VisualScriptLanguage::singleton->add_register_func("functions/get",create_node_generic<VisualScriptPropertyGet>); //VisualScriptLanguage::singleton->add_register_func("functions/call_script/call_self",create_script_call_node<VisualScriptScriptCall::CALL_MODE_SELF>); -// VisualScriptLanguage::singleton->add_register_func("functions/call_script/call_node",create_script_call_node<VisualScriptScriptCall::CALL_MODE_NODE_PATH>); + //VisualScriptLanguage::singleton->add_register_func("functions/call_script/call_node",create_script_call_node<VisualScriptScriptCall::CALL_MODE_NODE_PATH>); VisualScriptLanguage::singleton->add_register_func("functions/emit_signal",create_node_generic<VisualScriptEmitSignal>); diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index c9e24fc9d..f01284feb 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -1,6 +1,6 @@ #include "visual_script_nodes.h" #include "global_constants.h" -#include "globals.h" +#include "global_config.h" #include "scene/main/scene_main_loop.h" #include "os/os.h" #include "scene/main/node.h" @@ -539,11 +539,11 @@ Variant::Type VisualScriptOperator::get_typed() const { void VisualScriptOperator::_bind_methods() { - ClassDB::bind_method(_MD("set_operator","op"),&VisualScriptOperator::set_operator); - ClassDB::bind_method(_MD("get_operator"),&VisualScriptOperator::get_operator); + ClassDB::bind_method(D_METHOD("set_operator","op"),&VisualScriptOperator::set_operator); + ClassDB::bind_method(D_METHOD("get_operator"),&VisualScriptOperator::get_operator); - ClassDB::bind_method(_MD("set_typed","type"),&VisualScriptOperator::set_typed); - ClassDB::bind_method(_MD("get_typed"),&VisualScriptOperator::get_typed); + ClassDB::bind_method(D_METHOD("set_typed","type"),&VisualScriptOperator::set_typed); + ClassDB::bind_method(D_METHOD("get_typed"),&VisualScriptOperator::get_typed); String types; for(int i=0;i<Variant::OP_MAX;i++) { @@ -557,8 +557,8 @@ void VisualScriptOperator::_bind_methods() { argt+=","+Variant::get_type_name(Variant::Type(i)); } - ADD_PROPERTY(PropertyInfo(Variant::INT,"operator_value/type",PROPERTY_HINT_ENUM,types),_SCS("set_operator"),_SCS("get_operator")); - ADD_PROPERTY(PropertyInfo(Variant::INT,"typed_value/typed",PROPERTY_HINT_ENUM,argt),_SCS("set_typed"),_SCS("get_typed")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"operator_value/type",PROPERTY_HINT_ENUM,types),"set_operator","get_operator"); + ADD_PROPERTY(PropertyInfo(Variant::INT,"typed_value/typed",PROPERTY_HINT_ENUM,argt),"set_typed","get_typed"); } @@ -717,11 +717,11 @@ void VisualScriptVariableGet::_validate_property(PropertyInfo& property) const { void VisualScriptVariableGet::_bind_methods() { - ClassDB::bind_method(_MD("set_variable","name"),&VisualScriptVariableGet::set_variable); - ClassDB::bind_method(_MD("get_variable"),&VisualScriptVariableGet::get_variable); + ClassDB::bind_method(D_METHOD("set_variable","name"),&VisualScriptVariableGet::set_variable); + ClassDB::bind_method(D_METHOD("get_variable"),&VisualScriptVariableGet::get_variable); - ADD_PROPERTY(PropertyInfo(Variant::STRING,"variable/name"),_SCS("set_variable"),_SCS("get_variable")); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"variable/name"),"set_variable","get_variable"); } @@ -853,11 +853,11 @@ void VisualScriptVariableSet::_validate_property(PropertyInfo& property) const { void VisualScriptVariableSet::_bind_methods() { - ClassDB::bind_method(_MD("set_variable","name"),&VisualScriptVariableSet::set_variable); - ClassDB::bind_method(_MD("get_variable"),&VisualScriptVariableSet::get_variable); + ClassDB::bind_method(D_METHOD("set_variable","name"),&VisualScriptVariableSet::set_variable); + ClassDB::bind_method(D_METHOD("get_variable"),&VisualScriptVariableSet::get_variable); - ADD_PROPERTY(PropertyInfo(Variant::STRING,"variable/name"),_SCS("set_variable"),_SCS("get_variable")); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"variable/name"),"set_variable","get_variable"); } @@ -995,11 +995,11 @@ void VisualScriptConstant::_validate_property(PropertyInfo& property) const { void VisualScriptConstant::_bind_methods() { - ClassDB::bind_method(_MD("set_constant_type","type"),&VisualScriptConstant::set_constant_type); - ClassDB::bind_method(_MD("get_constant_type"),&VisualScriptConstant::get_constant_type); + ClassDB::bind_method(D_METHOD("set_constant_type","type"),&VisualScriptConstant::set_constant_type); + ClassDB::bind_method(D_METHOD("get_constant_type"),&VisualScriptConstant::get_constant_type); - ClassDB::bind_method(_MD("set_constant_value","value"),&VisualScriptConstant::set_constant_value); - ClassDB::bind_method(_MD("get_constant_value"),&VisualScriptConstant::get_constant_value); + ClassDB::bind_method(D_METHOD("set_constant_value","value"),&VisualScriptConstant::set_constant_value); + ClassDB::bind_method(D_METHOD("get_constant_value"),&VisualScriptConstant::get_constant_value); String argt="Null"; for(int i=1;i<Variant::VARIANT_MAX;i++) { @@ -1007,8 +1007,8 @@ void VisualScriptConstant::_bind_methods() { } - ADD_PROPERTY(PropertyInfo(Variant::INT,"constant/type",PROPERTY_HINT_ENUM,argt),_SCS("set_constant_type"),_SCS("get_constant_type")); - ADD_PROPERTY(PropertyInfo(Variant::NIL,"constant/value"),_SCS("set_constant_value"),_SCS("get_constant_value")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"constant/type",PROPERTY_HINT_ENUM,argt),"set_constant_type","get_constant_type"); + ADD_PROPERTY(PropertyInfo(Variant::NIL,"constant/value"),"set_constant_value","get_constant_value"); } @@ -1123,11 +1123,11 @@ Ref<Resource> VisualScriptPreload::get_preload() const{ void VisualScriptPreload::_bind_methods() { - ClassDB::bind_method(_MD("set_preload","resource"),&VisualScriptPreload::set_preload); - ClassDB::bind_method(_MD("get_preload"),&VisualScriptPreload::get_preload); + ClassDB::bind_method(D_METHOD("set_preload","resource"),&VisualScriptPreload::set_preload); + ClassDB::bind_method(D_METHOD("get_preload"),&VisualScriptPreload::get_preload); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT,"resource",PROPERTY_HINT_RESOURCE_TYPE,"Resource"),_SCS("set_preload"),_SCS("get_preload")); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT,"resource",PROPERTY_HINT_RESOURCE_TYPE,"Resource"),"set_preload","get_preload"); } @@ -1425,8 +1425,8 @@ VisualScriptNodeInstance* VisualScriptGlobalConstant::instance(VisualScriptInsta void VisualScriptGlobalConstant::_bind_methods() { - ClassDB::bind_method(_MD("set_global_constant","index"),&VisualScriptGlobalConstant::set_global_constant); - ClassDB::bind_method(_MD("get_global_constant"),&VisualScriptGlobalConstant::get_global_constant); + ClassDB::bind_method(D_METHOD("set_global_constant","index"),&VisualScriptGlobalConstant::set_global_constant); + ClassDB::bind_method(D_METHOD("get_global_constant"),&VisualScriptGlobalConstant::get_global_constant); String cc; @@ -1436,7 +1436,7 @@ void VisualScriptGlobalConstant::_bind_methods() { cc+=","; cc+=GlobalConstants::get_global_constant_name(i); } - ADD_PROPERTY(PropertyInfo(Variant::INT,"constant",PROPERTY_HINT_ENUM,cc),_SCS("set_global_constant"),_SCS("get_global_constant")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"constant",PROPERTY_HINT_ENUM,cc),"set_global_constant","get_global_constant"); } VisualScriptGlobalConstant::VisualScriptGlobalConstant() { @@ -1563,14 +1563,14 @@ void VisualScriptClassConstant::_validate_property(PropertyInfo& property) const void VisualScriptClassConstant::_bind_methods() { - ClassDB::bind_method(_MD("set_class_constant","name"),&VisualScriptClassConstant::set_class_constant); - ClassDB::bind_method(_MD("get_class_constant"),&VisualScriptClassConstant::get_class_constant); + ClassDB::bind_method(D_METHOD("set_class_constant","name"),&VisualScriptClassConstant::set_class_constant); + ClassDB::bind_method(D_METHOD("get_class_constant"),&VisualScriptClassConstant::get_class_constant); - ClassDB::bind_method(_MD("set_base_type","name"),&VisualScriptClassConstant::set_base_type); - ClassDB::bind_method(_MD("get_base_type"),&VisualScriptClassConstant::get_base_type); + ClassDB::bind_method(D_METHOD("set_base_type","name"),&VisualScriptClassConstant::set_base_type); + ClassDB::bind_method(D_METHOD("get_base_type"),&VisualScriptClassConstant::get_base_type); - ADD_PROPERTY(PropertyInfo(Variant::STRING,"base_type",PROPERTY_HINT_TYPE_STRING,"Object"),_SCS("set_base_type"),_SCS("get_base_type")); - ADD_PROPERTY(PropertyInfo(Variant::STRING,"constant",PROPERTY_HINT_ENUM,""),_SCS("set_class_constant"),_SCS("get_class_constant")); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"base_type",PROPERTY_HINT_TYPE_STRING,"Object"),"set_base_type","get_base_type"); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"constant",PROPERTY_HINT_ENUM,""),"set_class_constant","get_class_constant"); } VisualScriptClassConstant::VisualScriptClassConstant() { @@ -1703,11 +1703,11 @@ void VisualScriptBasicTypeConstant::_validate_property(PropertyInfo& property) c void VisualScriptBasicTypeConstant::_bind_methods() { - ClassDB::bind_method(_MD("set_basic_type","name"),&VisualScriptBasicTypeConstant::set_basic_type); - ClassDB::bind_method(_MD("get_basic_type"),&VisualScriptBasicTypeConstant::get_basic_type); + ClassDB::bind_method(D_METHOD("set_basic_type","name"),&VisualScriptBasicTypeConstant::set_basic_type); + ClassDB::bind_method(D_METHOD("get_basic_type"),&VisualScriptBasicTypeConstant::get_basic_type); - ClassDB::bind_method(_MD("set_basic_type_constant","name"),&VisualScriptBasicTypeConstant::set_basic_type_constant); - ClassDB::bind_method(_MD("get_basic_type_constant"),&VisualScriptBasicTypeConstant::get_basic_type_constant); + ClassDB::bind_method(D_METHOD("set_basic_type_constant","name"),&VisualScriptBasicTypeConstant::set_basic_type_constant); + ClassDB::bind_method(D_METHOD("get_basic_type_constant"),&VisualScriptBasicTypeConstant::get_basic_type_constant); String argt="Null"; @@ -1715,8 +1715,8 @@ void VisualScriptBasicTypeConstant::_bind_methods() { argt+=","+Variant::get_type_name(Variant::Type(i)); } - ADD_PROPERTY(PropertyInfo(Variant::INT,"basic_type",PROPERTY_HINT_ENUM,argt),_SCS("set_basic_type"),_SCS("get_basic_type")); - ADD_PROPERTY(PropertyInfo(Variant::STRING,"constant",PROPERTY_HINT_ENUM,""),_SCS("set_basic_type_constant"),_SCS("get_basic_type_constant")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"basic_type",PROPERTY_HINT_ENUM,argt),"set_basic_type","get_basic_type"); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"constant",PROPERTY_HINT_ENUM,""),"set_basic_type_constant","get_basic_type_constant"); } VisualScriptBasicTypeConstant::VisualScriptBasicTypeConstant() { @@ -1738,6 +1738,8 @@ const char* VisualScriptMathConstant::const_name[MATH_CONSTANT_MAX]={ "PI/2", "E", "Sqrt2", + "INF", + "NAN" }; double VisualScriptMathConstant::const_value[MATH_CONSTANT_MAX]={ @@ -1746,7 +1748,9 @@ double VisualScriptMathConstant::const_value[MATH_CONSTANT_MAX]={ Math_PI*2, Math_PI*0.5, 2.71828182845904523536, - Math::sqrt(2.0) + Math::sqrt(2.0), + Math_INF, + Math_NAN }; @@ -1831,8 +1835,8 @@ VisualScriptNodeInstance* VisualScriptMathConstant::instance(VisualScriptInstanc void VisualScriptMathConstant::_bind_methods() { - ClassDB::bind_method(_MD("set_math_constant","which"),&VisualScriptMathConstant::set_math_constant); - ClassDB::bind_method(_MD("get_math_constant"),&VisualScriptMathConstant::get_math_constant); + ClassDB::bind_method(D_METHOD("set_math_constant","which"),&VisualScriptMathConstant::set_math_constant); + ClassDB::bind_method(D_METHOD("get_math_constant"),&VisualScriptMathConstant::get_math_constant); String cc; @@ -1842,7 +1846,7 @@ void VisualScriptMathConstant::_bind_methods() { cc+=","; cc+=const_name[i]; } - ADD_PROPERTY(PropertyInfo(Variant::INT,"constant",PROPERTY_HINT_ENUM,cc),_SCS("set_math_constant"),_SCS("get_math_constant")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"constant",PROPERTY_HINT_ENUM,cc),"set_math_constant","get_math_constant"); } VisualScriptMathConstant::VisualScriptMathConstant() { @@ -1953,8 +1957,8 @@ VisualScriptEngineSingleton::TypeGuess VisualScriptEngineSingleton::guess_output void VisualScriptEngineSingleton::_bind_methods() { - ClassDB::bind_method(_MD("set_singleton","name"),&VisualScriptEngineSingleton::set_singleton); - ClassDB::bind_method(_MD("get_singleton"),&VisualScriptEngineSingleton::get_singleton); + ClassDB::bind_method(D_METHOD("set_singleton","name"),&VisualScriptEngineSingleton::set_singleton); + ClassDB::bind_method(D_METHOD("get_singleton"),&VisualScriptEngineSingleton::get_singleton); String cc; @@ -1971,7 +1975,7 @@ void VisualScriptEngineSingleton::_bind_methods() { cc+=E->get().name; } - ADD_PROPERTY(PropertyInfo(Variant::STRING,"constant",PROPERTY_HINT_ENUM,cc),_SCS("set_singleton"),_SCS("get_singleton")); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"constant",PROPERTY_HINT_ENUM,cc),"set_singleton","get_singleton"); } VisualScriptEngineSingleton::VisualScriptEngineSingleton() { @@ -2190,10 +2194,10 @@ void VisualScriptSceneNode::_validate_property(PropertyInfo& property) const { void VisualScriptSceneNode::_bind_methods() { - ClassDB::bind_method(_MD("set_node_path","path"),&VisualScriptSceneNode::set_node_path); - ClassDB::bind_method(_MD("get_node_path"),&VisualScriptSceneNode::get_node_path); + ClassDB::bind_method(D_METHOD("set_node_path","path"),&VisualScriptSceneNode::set_node_path); + ClassDB::bind_method(D_METHOD("get_node_path"),&VisualScriptSceneNode::get_node_path); - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH,"node_path",PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE),_SCS("set_node_path"),_SCS("get_node_path")); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH,"node_path",PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE),"set_node_path","get_node_path"); } VisualScriptSceneNode::VisualScriptSceneNode() { @@ -2401,10 +2405,10 @@ VisualScriptNodeInstance* VisualScriptResourcePath::instance(VisualScriptInstanc void VisualScriptResourcePath::_bind_methods() { - ClassDB::bind_method(_MD("set_resource_path","path"),&VisualScriptResourcePath::set_resource_path); - ClassDB::bind_method(_MD("get_resource_path"),&VisualScriptResourcePath::get_resource_path); + ClassDB::bind_method(D_METHOD("set_resource_path","path"),&VisualScriptResourcePath::set_resource_path); + ClassDB::bind_method(D_METHOD("get_resource_path"),&VisualScriptResourcePath::get_resource_path); - ADD_PROPERTY(PropertyInfo(Variant::STRING,"path",PROPERTY_HINT_FILE),_SCS("set_resource_path"),_SCS("get_resource_path")); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"path",PROPERTY_HINT_FILE),"set_resource_path","get_resource_path"); } VisualScriptResourcePath::VisualScriptResourcePath() { @@ -3001,18 +3005,18 @@ VisualScriptNodeInstance* VisualScriptComment::instance(VisualScriptInstance* p_ void VisualScriptComment::_bind_methods() { - ClassDB::bind_method(_MD("set_title","title"),&VisualScriptComment::set_title); - ClassDB::bind_method(_MD("get_title"),&VisualScriptComment::get_title); + ClassDB::bind_method(D_METHOD("set_title","title"),&VisualScriptComment::set_title); + ClassDB::bind_method(D_METHOD("get_title"),&VisualScriptComment::get_title); - ClassDB::bind_method(_MD("set_description","description"),&VisualScriptComment::set_description); - ClassDB::bind_method(_MD("get_description"),&VisualScriptComment::get_description); + ClassDB::bind_method(D_METHOD("set_description","description"),&VisualScriptComment::set_description); + ClassDB::bind_method(D_METHOD("get_description"),&VisualScriptComment::get_description); - ClassDB::bind_method(_MD("set_size","size"),&VisualScriptComment::set_size); - ClassDB::bind_method(_MD("get_size"),&VisualScriptComment::get_size); + ClassDB::bind_method(D_METHOD("set_size","size"),&VisualScriptComment::set_size); + ClassDB::bind_method(D_METHOD("get_size"),&VisualScriptComment::get_size); - ADD_PROPERTY( PropertyInfo(Variant::STRING,"title"),_SCS("set_title"),_SCS("get_title")); - ADD_PROPERTY( PropertyInfo(Variant::STRING,"description",PROPERTY_HINT_MULTILINE_TEXT),_SCS("set_description"),_SCS("get_description")); - ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"size"),_SCS("set_size"),_SCS("get_size")); + ADD_PROPERTY( PropertyInfo(Variant::STRING,"title"),"set_title","get_title"); + ADD_PROPERTY( PropertyInfo(Variant::STRING,"description",PROPERTY_HINT_MULTILINE_TEXT),"set_description","get_description"); + ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"size"),"set_size","get_size"); } @@ -3140,14 +3144,14 @@ VisualScriptNodeInstance* VisualScriptConstructor::instance(VisualScriptInstance void VisualScriptConstructor::_bind_methods() { - ClassDB::bind_method(_MD("set_constructor_type","type"),&VisualScriptConstructor::set_constructor_type); - ClassDB::bind_method(_MD("get_constructor_type"),&VisualScriptConstructor::get_constructor_type); + ClassDB::bind_method(D_METHOD("set_constructor_type","type"),&VisualScriptConstructor::set_constructor_type); + ClassDB::bind_method(D_METHOD("get_constructor_type"),&VisualScriptConstructor::get_constructor_type); - ClassDB::bind_method(_MD("set_constructor","constructor"),&VisualScriptConstructor::set_constructor); - ClassDB::bind_method(_MD("get_constructor"),&VisualScriptConstructor::get_constructor); + ClassDB::bind_method(D_METHOD("set_constructor","constructor"),&VisualScriptConstructor::set_constructor); + ClassDB::bind_method(D_METHOD("get_constructor"),&VisualScriptConstructor::get_constructor); - ADD_PROPERTY( PropertyInfo(Variant::INT,"type",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_constructor_type"),_SCS("get_constructor_type")); - ADD_PROPERTY( PropertyInfo(Variant::DICTIONARY,"constructor",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_constructor"),_SCS("get_constructor")); + ADD_PROPERTY( PropertyInfo(Variant::INT,"type",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_constructor_type","get_constructor_type"); + ADD_PROPERTY( PropertyInfo(Variant::DICTIONARY,"constructor",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_constructor","get_constructor"); } @@ -3283,19 +3287,19 @@ VisualScriptNodeInstance* VisualScriptLocalVar::instance(VisualScriptInstance* p void VisualScriptLocalVar::_bind_methods() { - ClassDB::bind_method(_MD("set_var_name","name"),&VisualScriptLocalVar::set_var_name); - ClassDB::bind_method(_MD("get_var_name"),&VisualScriptLocalVar::get_var_name); + ClassDB::bind_method(D_METHOD("set_var_name","name"),&VisualScriptLocalVar::set_var_name); + ClassDB::bind_method(D_METHOD("get_var_name"),&VisualScriptLocalVar::get_var_name); - ClassDB::bind_method(_MD("set_var_type","type"),&VisualScriptLocalVar::set_var_type); - ClassDB::bind_method(_MD("get_var_type"),&VisualScriptLocalVar::get_var_type); + ClassDB::bind_method(D_METHOD("set_var_type","type"),&VisualScriptLocalVar::set_var_type); + ClassDB::bind_method(D_METHOD("get_var_type"),&VisualScriptLocalVar::get_var_type); String argt="Any"; for(int i=1;i<Variant::VARIANT_MAX;i++) { argt+=","+Variant::get_type_name(Variant::Type(i)); } - ADD_PROPERTY( PropertyInfo(Variant::STRING,"variable/name"),_SCS("set_var_name"),_SCS("get_var_name")); - ADD_PROPERTY( PropertyInfo(Variant::INT,"variable/type",PROPERTY_HINT_ENUM,argt),_SCS("set_var_type"),_SCS("get_var_type")); + ADD_PROPERTY( PropertyInfo(Variant::STRING,"variable/name"),"set_var_name","get_var_name"); + ADD_PROPERTY( PropertyInfo(Variant::INT,"variable/type",PROPERTY_HINT_ENUM,argt),"set_var_type","get_var_type"); } @@ -3420,19 +3424,19 @@ VisualScriptNodeInstance* VisualScriptLocalVarSet::instance(VisualScriptInstance void VisualScriptLocalVarSet::_bind_methods() { - ClassDB::bind_method(_MD("set_var_name","name"),&VisualScriptLocalVarSet::set_var_name); - ClassDB::bind_method(_MD("get_var_name"),&VisualScriptLocalVarSet::get_var_name); + ClassDB::bind_method(D_METHOD("set_var_name","name"),&VisualScriptLocalVarSet::set_var_name); + ClassDB::bind_method(D_METHOD("get_var_name"),&VisualScriptLocalVarSet::get_var_name); - ClassDB::bind_method(_MD("set_var_type","type"),&VisualScriptLocalVarSet::set_var_type); - ClassDB::bind_method(_MD("get_var_type"),&VisualScriptLocalVarSet::get_var_type); + ClassDB::bind_method(D_METHOD("set_var_type","type"),&VisualScriptLocalVarSet::set_var_type); + ClassDB::bind_method(D_METHOD("get_var_type"),&VisualScriptLocalVarSet::get_var_type); String argt="Any"; for(int i=1;i<Variant::VARIANT_MAX;i++) { argt+=","+Variant::get_type_name(Variant::Type(i)); } - ADD_PROPERTY( PropertyInfo(Variant::STRING,"variable/name"),_SCS("set_var_name"),_SCS("get_var_name")); - ADD_PROPERTY( PropertyInfo(Variant::INT,"variable/type",PROPERTY_HINT_ENUM,argt),_SCS("set_var_type"),_SCS("get_var_type")); + ADD_PROPERTY( PropertyInfo(Variant::STRING,"variable/name"),"set_var_name","get_var_name"); + ADD_PROPERTY( PropertyInfo(Variant::INT,"variable/type",PROPERTY_HINT_ENUM,argt),"set_var_type","get_var_type"); } @@ -3615,7 +3619,7 @@ void VisualScriptInputAction::_validate_property(PropertyInfo& property) const { al.push_back(name); } - al.sort();; + al.sort(); for(int i=0;i<al.size();i++) { if (actions!=String()) @@ -3630,14 +3634,14 @@ void VisualScriptInputAction::_validate_property(PropertyInfo& property) const { void VisualScriptInputAction::_bind_methods() { - ClassDB::bind_method(_MD("set_action_name","name"),&VisualScriptInputAction::set_action_name); - ClassDB::bind_method(_MD("get_action_name"),&VisualScriptInputAction::get_action_name); + ClassDB::bind_method(D_METHOD("set_action_name","name"),&VisualScriptInputAction::set_action_name); + ClassDB::bind_method(D_METHOD("get_action_name"),&VisualScriptInputAction::get_action_name); - ClassDB::bind_method(_MD("set_action_mode","mode"),&VisualScriptInputAction::set_action_mode); - ClassDB::bind_method(_MD("get_action_mode"),&VisualScriptInputAction::get_action_mode); + ClassDB::bind_method(D_METHOD("set_action_mode","mode"),&VisualScriptInputAction::set_action_mode); + ClassDB::bind_method(D_METHOD("get_action_mode"),&VisualScriptInputAction::get_action_mode); - ADD_PROPERTY( PropertyInfo(Variant::STRING,"action"),_SCS("set_action_name"),_SCS("get_action_name")); - ADD_PROPERTY( PropertyInfo(Variant::INT,"mode",PROPERTY_HINT_ENUM,"Pressed,Released,JustPressed,JustReleased"),_SCS("set_action_mode"),_SCS("get_action_mode")); + ADD_PROPERTY( PropertyInfo(Variant::STRING,"action"),"set_action_name","get_action_name"); + ADD_PROPERTY( PropertyInfo(Variant::INT,"mode",PROPERTY_HINT_ENUM,"Pressed,Released,JustPressed,JustReleased"),"set_action_mode","get_action_mode"); } @@ -3705,7 +3709,7 @@ String VisualScriptDeconstruct::get_category() const { void VisualScriptDeconstruct::_update_elements() { - elements.clear();; + elements.clear(); Variant v; if (type==Variant::INPUT_EVENT) { InputEvent ie; @@ -3834,14 +3838,14 @@ void VisualScriptDeconstruct::_validate_property(PropertyInfo& property) const { void VisualScriptDeconstruct::_bind_methods() { - ClassDB::bind_method(_MD("set_deconstruct_type","type"),&VisualScriptDeconstruct::set_deconstruct_type); - ClassDB::bind_method(_MD("get_deconstruct_type"),&VisualScriptDeconstruct::get_deconstruct_type); + ClassDB::bind_method(D_METHOD("set_deconstruct_type","type"),&VisualScriptDeconstruct::set_deconstruct_type); + ClassDB::bind_method(D_METHOD("get_deconstruct_type"),&VisualScriptDeconstruct::get_deconstruct_type); - ClassDB::bind_method(_MD("set_deconstruct_input_type","input_type"),&VisualScriptDeconstruct::set_deconstruct_input_type); - ClassDB::bind_method(_MD("get_deconstruct_input_type"),&VisualScriptDeconstruct::get_deconstruct_input_type); + ClassDB::bind_method(D_METHOD("set_deconstruct_input_type","input_type"),&VisualScriptDeconstruct::set_deconstruct_input_type); + ClassDB::bind_method(D_METHOD("get_deconstruct_input_type"),&VisualScriptDeconstruct::get_deconstruct_input_type); - ClassDB::bind_method(_MD("_set_elem_cache","_cache"),&VisualScriptDeconstruct::_set_elem_cache); - ClassDB::bind_method(_MD("_get_elem_cache"),&VisualScriptDeconstruct::_get_elem_cache); + ClassDB::bind_method(D_METHOD("_set_elem_cache","_cache"),&VisualScriptDeconstruct::_set_elem_cache); + ClassDB::bind_method(D_METHOD("_get_elem_cache"),&VisualScriptDeconstruct::_get_elem_cache); String argt="Any"; for(int i=1;i<Variant::VARIANT_MAX;i++) { @@ -3850,9 +3854,9 @@ void VisualScriptDeconstruct::_bind_methods() { String iet="None,Key,MouseMotion,MouseButton,JoypadMotion,JoypadButton,ScreenTouch,ScreenDrag,Action"; - ADD_PROPERTY( PropertyInfo(Variant::INT,"type",PROPERTY_HINT_ENUM,argt),_SCS("set_deconstruct_type"),_SCS("get_deconstruct_type")); - ADD_PROPERTY( PropertyInfo(Variant::INT,"input_type",PROPERTY_HINT_ENUM,iet),_SCS("set_deconstruct_input_type"),_SCS("get_deconstruct_input_type")); - ADD_PROPERTY( PropertyInfo(Variant::ARRAY,"elem_cache",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_elem_cache"),_SCS("_get_elem_cache")); + ADD_PROPERTY( PropertyInfo(Variant::INT,"type",PROPERTY_HINT_ENUM,argt),"set_deconstruct_type","get_deconstruct_type"); + ADD_PROPERTY( PropertyInfo(Variant::INT,"input_type",PROPERTY_HINT_ENUM,iet),"set_deconstruct_input_type","get_deconstruct_input_type"); + ADD_PROPERTY( PropertyInfo(Variant::ARRAY,"elem_cache",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"_set_elem_cache","_get_elem_cache"); } diff --git a/modules/visual_script/visual_script_nodes.h b/modules/visual_script/visual_script_nodes.h index 7a06fbf5e..25d07ccb8 100644 --- a/modules/visual_script/visual_script_nodes.h +++ b/modules/visual_script/visual_script_nodes.h @@ -467,7 +467,9 @@ public: MATH_CONSTANT_HALF_PI, MATH_CONSTANT_E, MATH_CONSTANT_SQRT2, - MATH_CONSTANT_MAX, + MATH_CONSTANT_INF, + MATH_CONSTANT_NAN, + MATH_CONSTANT_MAX }; private: diff --git a/modules/visual_script/visual_script_yield_nodes.cpp b/modules/visual_script/visual_script_yield_nodes.cpp index 8b251e667..c07960667 100644 --- a/modules/visual_script/visual_script_yield_nodes.cpp +++ b/modules/visual_script/visual_script_yield_nodes.cpp @@ -157,14 +157,14 @@ void VisualScriptYield::_validate_property(PropertyInfo& property) const { void VisualScriptYield::_bind_methods() { - ClassDB::bind_method(_MD("set_yield_mode","mode"),&VisualScriptYield::set_yield_mode); - ClassDB::bind_method(_MD("get_yield_mode"),&VisualScriptYield::get_yield_mode); + ClassDB::bind_method(D_METHOD("set_yield_mode","mode"),&VisualScriptYield::set_yield_mode); + ClassDB::bind_method(D_METHOD("get_yield_mode"),&VisualScriptYield::get_yield_mode); - ClassDB::bind_method(_MD("set_wait_time","sec"),&VisualScriptYield::set_wait_time); - ClassDB::bind_method(_MD("get_wait_time"),&VisualScriptYield::get_wait_time); + ClassDB::bind_method(D_METHOD("set_wait_time","sec"),&VisualScriptYield::set_wait_time); + ClassDB::bind_method(D_METHOD("get_wait_time"),&VisualScriptYield::get_wait_time); - ADD_PROPERTY(PropertyInfo(Variant::INT,"mode",PROPERTY_HINT_ENUM,"Frame,FixedFrame,Time",PROPERTY_USAGE_NOEDITOR),_SCS("set_yield_mode"),_SCS("get_yield_mode")); - ADD_PROPERTY(PropertyInfo(Variant::REAL,"wait_time"),_SCS("set_wait_time"),_SCS("get_wait_time")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"mode",PROPERTY_HINT_ENUM,"Frame,FixedFrame,Time",PROPERTY_USAGE_NOEDITOR),"set_yield_mode","get_yield_mode"); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"wait_time"),"set_wait_time","get_wait_time"); BIND_CONSTANT( YIELD_FRAME ); @@ -468,17 +468,17 @@ void VisualScriptYieldSignal::_validate_property(PropertyInfo& property) const { void VisualScriptYieldSignal::_bind_methods() { - ClassDB::bind_method(_MD("set_base_type","base_type"),&VisualScriptYieldSignal::set_base_type); - ClassDB::bind_method(_MD("get_base_type"),&VisualScriptYieldSignal::get_base_type); + ClassDB::bind_method(D_METHOD("set_base_type","base_type"),&VisualScriptYieldSignal::set_base_type); + ClassDB::bind_method(D_METHOD("get_base_type"),&VisualScriptYieldSignal::get_base_type); - ClassDB::bind_method(_MD("set_signal","signal"),&VisualScriptYieldSignal::set_signal); - ClassDB::bind_method(_MD("get_signal"),&VisualScriptYieldSignal::get_signal); + ClassDB::bind_method(D_METHOD("set_signal","signal"),&VisualScriptYieldSignal::set_signal); + ClassDB::bind_method(D_METHOD("get_signal"),&VisualScriptYieldSignal::get_signal); - ClassDB::bind_method(_MD("set_call_mode","mode"),&VisualScriptYieldSignal::set_call_mode); - ClassDB::bind_method(_MD("get_call_mode"),&VisualScriptYieldSignal::get_call_mode); + ClassDB::bind_method(D_METHOD("set_call_mode","mode"),&VisualScriptYieldSignal::set_call_mode); + ClassDB::bind_method(D_METHOD("get_call_mode"),&VisualScriptYieldSignal::get_call_mode); - ClassDB::bind_method(_MD("set_base_path","base_path"),&VisualScriptYieldSignal::set_base_path); - ClassDB::bind_method(_MD("get_base_path"),&VisualScriptYieldSignal::get_base_path); + ClassDB::bind_method(D_METHOD("set_base_path","base_path"),&VisualScriptYieldSignal::set_base_path); + ClassDB::bind_method(D_METHOD("get_base_path"),&VisualScriptYieldSignal::get_base_path); @@ -490,10 +490,10 @@ void VisualScriptYieldSignal::_bind_methods() { bt+=Variant::get_type_name(Variant::Type(i)); } - ADD_PROPERTY(PropertyInfo(Variant::INT,"signal/call_mode",PROPERTY_HINT_ENUM,"Self,Node Path,Instance"),_SCS("set_call_mode"),_SCS("get_call_mode")); - ADD_PROPERTY(PropertyInfo(Variant::STRING,"signal/base_type",PROPERTY_HINT_TYPE_STRING,"Object"),_SCS("set_base_type"),_SCS("get_base_type")); - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH,"signal/node_path",PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE),_SCS("set_base_path"),_SCS("get_base_path")); - ADD_PROPERTY(PropertyInfo(Variant::STRING,"signal/signal"),_SCS("set_signal"),_SCS("get_signal")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"signal/call_mode",PROPERTY_HINT_ENUM,"Self,Node Path,Instance"),"set_call_mode","get_call_mode"); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"signal/base_type",PROPERTY_HINT_TYPE_STRING,"Object"),"set_base_type","get_base_type"); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH,"signal/node_path",PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE),"set_base_path","get_base_path"); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"signal/signal"),"set_signal","get_signal"); BIND_CONSTANT( CALL_MODE_SELF ); diff --git a/modules/vorbis/audio_stream_ogg_vorbis.cpp b/modules/vorbis/audio_stream_ogg_vorbis.cpp index 7abcd0a8b..98920954a 100644 --- a/modules/vorbis/audio_stream_ogg_vorbis.cpp +++ b/modules/vorbis/audio_stream_ogg_vorbis.cpp @@ -78,7 +78,7 @@ int AudioStreamPlaybackOGGVorbis::_ov_seek_func(void *_f,ogg_int64_t offs, int w } int AudioStreamPlaybackOGGVorbis::_ov_close_func(void *_f) { -// printf("close %p\n",_f); + //printf("close %p\n",_f); if (!_f) return 0; FileAccess *fa=(FileAccess*)_f; @@ -141,7 +141,7 @@ int AudioStreamPlaybackOGGVorbis::mix(int16_t* p_bufer,int p_frames) { int errv = ov_open_callbacks(f,&vf,NULL,0,_ov_callbacks); if (errv!=0) { playing=false; - break;; // :( + break; // :( } if (loop_restart_time) { @@ -419,7 +419,7 @@ void ResourceFormatLoaderAudioStreamOGGVorbis::get_recognized_extensions(List<St } String ResourceFormatLoaderAudioStreamOGGVorbis::get_resource_type(const String &p_path) const { - if (p_path.extension().to_lower()=="ogg") + if (p_path.get_extension().to_lower()=="ogg") return "AudioStreamOGGVorbis"; return ""; } diff --git a/modules/vorbis/config.py b/modules/vorbis/config.py index fb920482f..ef5daca05 100644 --- a/modules/vorbis/config.py +++ b/modules/vorbis/config.py @@ -1,6 +1,7 @@ def can_build(platform): - return True +# return True + return False def configure(env): diff --git a/modules/webm/config.py b/modules/webm/config.py index fb920482f..ef5daca05 100644 --- a/modules/webm/config.py +++ b/modules/webm/config.py @@ -1,6 +1,7 @@ def can_build(platform): - return True +# return True + return False def configure(env): diff --git a/modules/webm/video_stream_webm.cpp b/modules/webm/video_stream_webm.cpp index d132e8969..d4995ad79 100644 --- a/modules/webm/video_stream_webm.cpp +++ b/modules/webm/video_stream_webm.cpp @@ -35,7 +35,7 @@ #include "../theora/yuv2rgb.h" #include "os/file_access.h" -#include "globals.h" +#include "global_config.h" #include <string.h> @@ -415,7 +415,7 @@ bool ResourceFormatLoaderVideoStreamWebm::handles_type(const String &p_type) con String ResourceFormatLoaderVideoStreamWebm::get_resource_type(const String &p_path) const { - const String exl = p_path.extension().to_lower(); + const String exl = p_path.get_extension().to_lower(); if (exl == "webm") return "VideoStreamWebm"; return ""; diff --git a/modules/webp/SCsub b/modules/webp/SCsub index 92f34c4da..aa3486a2c 100644 --- a/modules/webp/SCsub +++ b/modules/webp/SCsub @@ -9,108 +9,118 @@ env_webp = env_modules.Clone() if (env['builtin_libwebp'] != 'no'): thirdparty_dir = "#thirdparty/libwebp/" thirdparty_sources = [ - "enc/webpenc.c", - "enc/near_lossless.c", - "enc/frame.c", - "enc/alpha.c", - "enc/picture_csp.c", - "enc/vp8l.c", - "enc/picture_psnr.c", - "enc/delta_palettization.c", - "enc/syntax.c", - "enc/backward_references.c", - "enc/token.c", - "enc/analysis.c", - "enc/iterator.c", - "enc/picture_tools.c", - "enc/picture_rescale.c", - "enc/config.c", - "enc/tree.c", - "enc/cost.c", - "enc/picture.c", - "enc/quant.c", - "enc/filter.c", - "enc/histogram.c", - "utils/rescaler.c", - "utils/filters.c", - "utils/quant_levels_dec.c", - "utils/huffman.c", - "utils/thread.c", - "utils/quant_levels.c", - "utils/bit_writer.c", - "utils/bit_reader.c", - "utils/random.c", - "utils/utils.c", - "utils/huffman_encode.c", - "utils/color_cache.c", - "mux/muxinternal.c", - "mux/muxread.c", - "mux/anim_encode.c", - "mux/muxedit.c", - "dec/webp.c", - "dec/frame.c", - "dec/alpha.c", - "dec/vp8l.c", - "dec/io.c", - "dec/vp8.c", - "dec/idec.c", - "dec/tree.c", - "dec/buffer.c", - "dec/quant.c", - "demux/demux.c", + "dec/alpha_dec.c", + "dec/buffer_dec.c", + "dec/frame_dec.c", + "dec/idec_dec.c", + "dec/io_dec.c", + "dec/quant_dec.c", + "dec/tree_dec.c", + "dec/vp8_dec.c", + "dec/vp8l_dec.c", + "dec/webp_dec.c", "demux/anim_decode.c", - "dsp/yuv.c", - "dsp/filters_sse2.c", - "dsp/dec_sse41.c", - "dsp/rescaler.c", - "dsp/lossless_sse2.c", - "dsp/alpha_processing_sse41.c", - "dsp/alpha_processing_sse2.c", - "dsp/filters.c", - "dsp/upsampling_mips_dsp_r2.c", - "dsp/dec_neon.c", - "dsp/enc_neon.c", - "dsp/lossless_enc_mips32.c", - "dsp/lossless_enc_sse2.c", - "dsp/upsampling.c", - "dsp/lossless_enc_neon.c", + "demux/demux.c", "dsp/alpha_processing.c", + "dsp/alpha_processing_mips_dsp_r2.c", + "dsp/alpha_processing_neon.c", + "dsp/alpha_processing_sse2.c", + "dsp/alpha_processing_sse41.c", + "dsp/argb.c", + "dsp/argb_mips_dsp_r2.c", + "dsp/argb_sse2.c", + "dsp/cost.c", + "dsp/cost_mips32.c", + "dsp/cost_mips_dsp_r2.c", "dsp/cost_sse2.c", + "dsp/cpu.c", + "dsp/dec.c", + "dsp/dec_clip_tables.c", "dsp/dec_mips32.c", + "dsp/dec_mips_dsp_r2.c", + "dsp/dec_msa.c", + "dsp/dec_neon.c", + "dsp/dec_sse2.c", + "dsp/dec_sse41.c", "dsp/enc_avx2.c", - "dsp/rescaler_mips32.c", "dsp/enc.c", - "dsp/lossless_enc_sse41.c", - "dsp/cost_mips32.c", - "dsp/lossless_mips_dsp_r2.c", - "dsp/filters_mips_dsp_r2.c", - "dsp/upsampling_neon.c", - "dsp/alpha_processing_mips_dsp_r2.c", + "dsp/enc_mips32.c", "dsp/enc_mips_dsp_r2.c", - "dsp/lossless.c", - "dsp/yuv_mips_dsp_r2.c", - "dsp/cost_mips_dsp_r2.c", - "dsp/argb.c", - "dsp/dec_sse2.c", - "dsp/rescaler_sse2.c", + "dsp/enc_msa.c", + "dsp/enc_neon.c", + "dsp/enc_sse2.c", "dsp/enc_sse41.c", - "dsp/argb_mips_dsp_r2.c", + "dsp/filters.c", + "dsp/filters_mips_dsp_r2.c", + "dsp/filters_msa.c", + "dsp/filters_neon.c", + "dsp/filters_sse2.c", + "dsp/lossless.c", + "dsp/lossless_enc.c", + "dsp/lossless_enc_mips32.c", "dsp/lossless_enc_mips_dsp_r2.c", - "dsp/dec_clip_tables.c", - "dsp/yuv_mips32.c", - "dsp/cpu.c", - "dsp/dec.c", - "dsp/argb_sse2.c", + "dsp/lossless_enc_msa.c", + "dsp/lossless_enc_neon.c", + "dsp/lossless_enc_sse2.c", + "dsp/lossless_enc_sse41.c", + "dsp/lossless_mips_dsp_r2.c", + "dsp/lossless_msa.c", "dsp/lossless_neon.c", - "dsp/lossless_enc.c", - "dsp/enc_mips32.c", - "dsp/cost.c", + "dsp/lossless_sse2.c", + "dsp/rescaler.c", + "dsp/rescaler_mips32.c", "dsp/rescaler_mips_dsp_r2.c", - "dsp/dec_mips_dsp_r2.c", + "dsp/rescaler_msa.c", "dsp/rescaler_neon.c", - "dsp/yuv_sse2.c", - "dsp/enc_sse2.c", + "dsp/rescaler_sse2.c", + "dsp/upsampling.c", + "dsp/upsampling_mips_dsp_r2.c", + "dsp/upsampling_msa.c", + "dsp/upsampling_neon.c", "dsp/upsampling_sse2.c", + "dsp/yuv.c", + "dsp/yuv_mips32.c", + "dsp/yuv_mips_dsp_r2.c", + "dsp/yuv_sse2.c", + "enc/alpha_enc.c", + "enc/analysis_enc.c", + "enc/backward_references_enc.c", + "enc/config_enc.c", + "enc/cost_enc.c", + "enc/delta_palettization_enc.c", + "enc/filter_enc.c", + "enc/frame_enc.c", + "enc/histogram_enc.c", + "enc/iterator_enc.c", + "enc/near_lossless_enc.c", + "enc/picture_csp_enc.c", + "enc/picture_enc.c", + "enc/picture_psnr_enc.c", + "enc/picture_rescale_enc.c", + "enc/picture_tools_enc.c", + "enc/predictor_enc.c", + "enc/quant_enc.c", + "enc/syntax_enc.c", + "enc/token_enc.c", + "enc/tree_enc.c", + "enc/vp8l_enc.c", + "enc/webp_enc.c", + "mux/anim_encode.c", + "mux/muxedit.c", + "mux/muxinternal.c", + "mux/muxread.c", + "utils/bit_reader_utils.c", + "utils/bit_writer_utils.c", + "utils/color_cache_utils.c", + "utils/filters_utils.c", + "utils/huffman_encode_utils.c", + "utils/huffman_utils.c", + "utils/quant_levels_dec_utils.c", + "utils/quant_levels_utils.c", + "utils/random_utils.c", + "utils/rescaler_utils.c", + "utils/thread_utils.c", + "utils/utils.c", ] thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] |
